0

in a bash script when I tried to access "~/" it's not working.

Example: touch "~/anything" results with

touch: cannot touch '~/anything': No such file or directory

What the heck? I can do it from the command prompt I'm running the script from.

user3161924
  • 261
  • 1
  • 8

2 Answers2

2

In Bash, The tilde or ~ is not expanded to /home/user when inside of double or single quotes.

If you need to use quotes to account for whitespace or special characters, then don't quote the tilde or the forward slash. For example:

touch ~/"that file"

touch ~/'this"quote'

You can also just use:

touch "$HOME/file with spaces"
Nasir Riley
  • 11,422
0

The quotes are the problem, if you use quotes with the ~ it seems to be using it as is instead of expanding it.

user3161924
  • 261
  • 1
  • 8