Because bash returns me that != is invalid, but it's a basic operator.
I try to use it in a three expression for loop
for (( c=1; ${!c}!=""; c++ ))
do
Because bash returns me that != is invalid, but it's a basic operator.
I try to use it in a three expression for loop
for (( c=1; ${!c}!=""; c++ ))
do
You can, but it's not really the usual way to check if there are empty arguments.
for((i=1; i<=$#; ++i)); do
[[ "${!i}" ]] || echo "$0: Argument $i is empty" >&2
done
If you don't care about the index, just looping over the actual arguments is even simpler.
for arg in "$@"; do
[[ "$arg" ]] || echo "$0: Empty argument" >&2
done
Notice how we print diagnostics to standard error, and take care to include the name of the script which generates the diagnostic in the message.
You very rarely need to check for empty arguments in practice, but perhaps this is a learning exercise.
You can't do string comparison in a (())
because it's only arithmetic.
What you could do is something like this, where the string check is separate test after incrementing the counter var:
c=0
while (( c += 1 )) && [[ -n ${!c} ]]; do
echo "$c ${!c}"
done