3 ms·
Auto-splitting variables is for passing arguments to a command you'll be using multiple times, or that you need to change under some condition, for example:
by Izkata 3y ago
Auto-splitting variables is for passing arguments to a command you'll be using multiple times, or that you need to change under some condition, for example:
RSYNC_ARGS='--progress --human-readable --human-readable'
if some_condition; then RSYNC_ARGS="$RSYNC_ARGS --exclude-from=some_file"; fi
rsync $RSYNC_ARGS foo bar
I can't think of a use for $* though and would guess it probably existed before $@ and is still there just for backwards compatibility.
- stabbles 3y agoThat's equally problematic... '--progress=yes please' with whitespace runs into problems. In Bash you can use arrays though: args+=('--progress=yes please')
- Izkata 3y agoSee last point about backwards compatibility. Arrays did come later. The array style probably should always be used nowadays (don't forget you also need to insert it into the command like ${args[@]}), but I learned before it was common (possibly before it was a thing, I'm having trouble finding exactly when basic arrays were added to bash) so I still use the string style when I know I won't need it.