Did you ever stop to think about how much it costs a cell (in terms of energy
and resources) to make a protein?
For an average size protein (300 amino acids long) it takes about 1350 ATP's,
1650 carbon atoms and 540 nitrogen atoms! And that's just for one polypeptide.(small
protein)
Escherichia coli has about 4000 genes that code for about 2000 proteins-- think of
all the energy and resources it would require if all the proteins were made
all the time!
Because protein synthesis is a huge commitment of energy and resources,
bacteria (and eukaryotes, too) have evolved elaborate mechanisms to control
which proteins are made at any given time, in any given environment. This
is genetic regulation.
Transcriptional control
According to the Central Dogma,
all cells transcribe
RNA from DNA, and translate proteins from mRNA. Bacteria make the most of
their resources by controlling protein synthesis from the level of transcription.
That is, mRNA is only transcribed when a protein is needed; when a protein
is NOT needed, the mRNA is not made.

Because the enzyme, RNA polymerase, carries out transcription, bacteria
have a number of ways to either help RNA polymerase or stop it from doing
it's job. This is done by using regulatory proteins that bind to DNA near
promoter regions. These regulatory proteins switch back and forth between
active and inactive conformations (shapes). In the active shape, the regulatory
proteins bind to DNA; in the inactive shape, they cannot bind DNA. The presence
or absence this small "signal" or effector molecule causes the
regulatory proteins to change from one conformation to the other.
Now that you've read about it, watch the central dogma animation!