The bacterial cell wall, primarily composed of peptidoglycan, provides structural support and determines the shape of the bacteria. Variations in the composition and thickness of the peptidoglycan layer contribute to the different shapes and rigidity of the bacterial cell wall.