What is the most idiomatic way in Bash to test if no positional parameters are given? There are so many ways to check this, I wonder if there is one preferred way.
S
Here's a most logical way:
[ ! $@ ]
It is based on a single rule:
[ ] # this returns 1
Well then,
[ ! ] # this returns 0
The rest is obvious: $@ is the special parameter that expands to a list of all positional parameters.
Test: (It will work even if you throw a couple of empty strings ("" "" "") at it.)
if [ ! $@ ]; then
printf 'Note: No arguments are given.'
fi