Problem Statement
What does $@ represent in a shell script?
Explanation
Special variables for arguments: $0 (script name), $1-$9 (first 9 arguments, ${10} for 10th onward), $# (number of arguments), $@ (all arguments as separate words), $* (all arguments as single word), $? (exit status of last command). Use "$@" (quoted) to preserve individual arguments correctly, especially with spaces.
Example: script.sh arg1 'arg 2' arg3 gives $1=arg1, $2=arg 2, $3=arg3, $#=3. Loop through arguments: for arg in "$@"; do echo "$arg"; done. Shift removes first argument moving others down: shift makes $2 become $1. Use shift to process arguments in loops.
Difference between $@ and $*: "$@" expands to "$1" "$2" "$3" (separate words), "$*" expands to "$1 $2 $3" (single word with IFS separator). Always quote "$@" to handle arguments with spaces correctly. Check argument count: if [ $# -eq 0 ]; then echo 'No arguments'; exit 1; fi. Understanding argument handling is essential for creating flexible, reusable scripts.
