difference b/t the exit codes $* and $@

I know that the exit codes in scripting "$*" will returns all the parameters/arguments passwd to the script.

But I also know that "$@" will also returns the same. What is the difference between those two [ $* and $@ ] ?

"$*" and "$@" are not exit codes; they are the command line arguments.

Exit codes are stored in "$?".

When unquoted, $* and $@ are the same; each word in the argument list becomes a separate word.

When quoted, "$*" returns a single argument containing all the command-line arguments; "$@" presents each command-line argument as a separate argument.

For a demonstration, put the following into a script and exceute it with the arguments: a "b c" "d e f" g.

printf "\n%s\n" "Using \$\*:"
printf "%s\n" $*

printf "\n%s\n" "Using \$\@:"
printf "%s\n" $@

printf "\n%s\n" "Using \"\$\*\":"
printf "%s\n" "$*"

printf "\n%s\n" "Using \"\$\@\":"
printf "%s\n" "$@"
1 Like