Bash — Escape spaces in results of `pwd` command

Just wrap the `pwd` in quotes to escape spaces. It’s just literally wrapping the output of pwd in a string “”.

$ > scp `pwd`/my_file.png foo # reads pwd spaces as argument separator
$ > scp "`pwd`"/my_file.png foo 

3 thoughts on “Bash — Escape spaces in results of `pwd` command

    1. They key part of this post is wrapping the command in quotes.

      Just executing `pwd` is the same as typing the output of that command, so

      ~/playground/space in foldername$ `pwd`

      Is the same as typing
      ~/playground/space in foldername

      Which will result in “no such file or directory”, wheras wrapping in quotes will result in the command w/ spaces:

      “`pwd`”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s