x=('hello world' "HELLO")
Both ${#x[*]}
and ${#x[@]}
print the same output.
I understand the difference between $@
and $*
but I am interested to see the difference without command line arguments.
x=('hello world' "HELLO")
Both ${#x[*]}
and ${#x[@]}
print the same output.
I understand the difference between $@
and $*
but I am interested to see the difference without command line arguments.
Always use @ expansion unless you have reason to use *. @ was added to work around a problem.
The two don't ALWAYS expand the same. The troubles involving* start with spaces and other shell metacharacters (quotes in particular, but $ and more as well).
The * leaves the metacharacters open for the shell to process them again, which is usually bad if you went out of your way to get them into the array. The @ protects them by expanding each array element as if it was a separately quoted value, leaving all metacharacters intact.