xinit_line=`grep '^xinit' /usr/X11R6/bin/startx | sed -e 's/\\$/\\\\\$/g'`; echo $xinit_line
This line is submitted to bash two times. In the first, when executing "xinit_line=..." it removes the apostrophe and pass "sed -e s/\$/\\\$/g" to the sub-shell called to do the substitution, requested by the grave accents. This sub-shell looks the sed and interprets it as "sed -d /$/\$/g", and pass it to sed process. Sed understands you want to append a dollar sign at the end of the line.