I’m trying in a shell script to copy a predefined set of Chrome bookmarks to the location where Chrome keeps them on a Mac (~/Library/Application Support/Google/Chrome/Default). In the script I have:
#!/bin/sh
bookmarks_dir="$HOME/Library/Application\ Support/Google/Chrome/Default"
cp -v "bookmarks/Bookmarks" "$bookmarks_dir"
But when I run this I get:
cp: /Users/aparkin/Library/Application\ Support/Google/Chrome/Default: No such file or directory
If I copy & paste the path in the error message above and do the cp by hand:
cp -v bookmarks/Bookmarks /Users/aparkin/Library/Application\ Support/Google/Chrome/Default
It copies fine, so the directory does in fact exist. It seems to be the space in the path that’s tripping things up.
What am I missing? I thought if a variable is enclosed in quotes that spaces in filenames no longer cause problems?
Get rid of the
\in the$bookmarks_dirdefinition. It’s being treated as a literal\: if you did an$echo bookmarks_diryou’d see it.The
\is only useful if you won’t put quotes around the string. So,would also work.