3 ms·
Always use "$@" foo() { for arg in "$@" ; do echo "arg is \"${arg}\"" done } foo 'bar baz' 'spaces in filename.txt' >
by pdkl95 11y ago
Always use "$@"
foo() {
for arg in "$@" ; do
echo "arg is \"${arg}\""
done
}
foo 'bar baz' 'spaces in filename.txt'
> dashes in filenames.
When writing shell scripts it's a good idea to use the -- option whenever possible
stupid_backup() {
cp -a -- "$@" /stupid/backup/dir/
}
# copies 2 files
stupid_backup --files '-with -leading -dashes'
- fnbr 11y agoWhat does the -- option do? I haven't encountered that before.
- QuercusMax 11y agoIt means "everything past here should not be parsed as a - or -- flag". If you have a file named "-l", then ls -- -l will show you that file, instead of doing a long listing.