Escape spaces with sed

When dealing with file paths, you may need to escape spaces. You can do this using sed.


p = "/var/lib/vmware/Virtual Machines"
echo $p
q = $(echo $p | sed 's/ /\\ /g')
echo $q


/var/lib/vmware/Virtual Machines
/var/lib/vmware/Virtual\ Machines

Last modified: 11/05/2007 Tags:

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top