Reasons for Bacteria with different shapes as given in Wikipedia/Bacteria:
The wide variety of shapes is determined by the bacterial cell wall and cytoskeleton, and is important because it can influence the
ability of bacteria to acquire nutrients, attach to surfaces, swim
through liquids and escape predators.
There is an article based on research by Kevin D. Young Bacterial morphology: Why have different shapes? which highlights 3 main points which defines the shape of Bacteria:
- Nutrient uptake: Cell shape, in and of itself, affects nutrient acquisition and argues that other nutritional situations may create conditions that favor one bacterial shape over another.
- Motility: Motility imposes a heavy selective pressure on cell shape. Fast cells are better off as rods with a certain length-to-width ratio, chemotactic cells must adopt shape ratios in line with their environments, and cells that forage near surfaces or navigate viscous environments may do best if they are slightly curved or spiral.
- Predation: In their struggle against being eaten, bacteria have adopted morphological defenses that may have produced the wealth of shapes we now observe.
These factors play a role in shaping bacteria. Further he explains what in general gives the shape to bacteria:
Bacterial morphology is affected by a combination of selective pressures - access to nutrients, cell division, attachment/dispersal, predation and motility (among others). Among these different factors, our understanding of the relationship between motility and cell shape is most complete; for example, highly motile bacteria are usually rods with a specific (optimal) shape and size, and movement through viscous fluids seems to a favor spiral shape. But since multiple selective forces are always in play, there is at the moment no way to predict cell shape based on the environment or vice versa.
Shape Matters: Why bacteria care how they look - This article highlights Kevin's work explaining why shapes matter for bacteria and they take it seriously for survival.
So adaptations to various environments could be possible but depending upon the environment we can not predict the shape of bacteria because some other factor might have played major role in giving shape to it. But the above mentioned 3 main factors gives some explanation.