Quote:
Originally posted by suchi_s
why do we write these commands in single quotes.. they work without them also..
|
If you have the sed command without quotes, the shell will try to
expand wildcards and shell/environment variables. So the shell looks in the sed command for special characters (like *[]$) to replace them according to shell expansion mechanisms. With sed, most often you do not want the shell to change your sed-command. Sed-commands often contain special regular expression characters like $[].*. If you do not quote the sed command, the shell will mess them up.
In your case, you don't use special regular expression characters specific to sed. In your case, you even
do want the shell to change your sed-command (expand the variable).
When you use sed for less simple tasks (i.e. real regexp's instead of your fixed strings), which is often the case when sed is used, you do need to use single quotes, to prevent the shell from touching them.
So, it's considered a good idea to always single-quote sed-commands, and make the exception for the parts you do need the shell to process them. So jlliagre's way of quoting your sed command may look more complex then needed. But that's just your (relatively simple) case of fixed string replacement with sed. jlliagre's quoting does show the best way to make your habit when using sed: Single-quote everything, except the part you do need the shell to change.