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 Comments

  1. stupidfool says:

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

    1. Yuji says:

      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 to Yuji Cancel reply