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 


  1. ~/playground/space in foldername$ `pwd`
    -bash: /Users//playground/space: No such file or directory

    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:


Leave a Comment

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s