Posts

Showing posts from January 11, 2019

How to have a script work with “$@” or a default list of parameters while not breaking paths with...

Image
6 I want a script that will run another utility over some default paths if no parameters are passed to it; ideally I want this safe for paths that contain spaces. So far I have script.sh : #!/bin/sh base=$(dirname "$0") exec touch "${@:-"$base/aaa" "$base/bbb"}" If I put this into a folder called "foo bar" and run it as: foo bar/script.sh I want it to should end up doing: touch foo bar/aaa foo bar/bbb i.e. create files "aaa" and "bbb" under "foo bar", the directory in which the script is located. Instead I get the error touch: cannot touch 'foo bar/aaa foo bar/bbb': No such file or directory (If I pass in parameters to the script it seems to work fine. Presumably removing the outer quotes in the la