We model the effects of shocks on the diffuse, X-ray-emitting baryons in clusters of galaxies. Shocks separate the infalling from the inner gas nearly at equilibrium and dominate the compression and the density gradients of the latter in the dark matter potential of the cluster. We find that, independently of the detailed shape of the potential, the density gradient is steeper and the compression factor larger for the richer clusters. We show, considering the different merging histories, that in the hierarchical cosmogony the above effects lead, in X-rays, to a luminosity-temperature relation L proportional to T-5 at the scale of groups that flattens down to L proportional to T-3 for rich clusters in accord with the observations and then saturates toward L proportional to T-2 for higher temperatures. From the merging histories, we also compute statistical fluctuations of the L-T correlation.