This one has me flummoxed.
I'm creating a Bash script which copies files into a series of repos and then adds them for commit. The files sometimes have spaces in the filenames, so they need to be quoted.
I've created a quoted space-separated list of filenames in a variable in Bash: $x
. When I run echo $x
I get this:
'test 01.sql' 'test 02.sql' 'test_03.sql'
If I manually run the following (in the appropriate directory), I have no problem:
git add 'test 01.sql' 'test 02.sql' 'test_03.sql'
But in my script, if I run:
git add $x
or git add "$x"
or git add "${x}"
, I get a fatal pathspec error from Git.
fatal: pathspec ''test 01.sql' 'test 02.sql' 'test_03.sql'' did not match any files
I've tried both single and double quoted strings with no difference.
The example has been simplified. The full version uses absolute paths to the files.
'/Volumes/HardDrive/Repo/queries/test 01.sql' '/Volumes/HardDrive/Repo/queries/test 02.sql' '/Volumes/HardDrive/Repo/queries/test_03.sql'
It works when echoed from the script and pasted manually into the git add command, but doesn't work when passed from a variable in the script.