-2

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.

1
  • ${#...} doesn't subject the contents of the array to further shell expansion, so those two expressions are identical. Commented Oct 29, 2016 at 13:40

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.