$1, $2, …), but when the number of parameters varies, special variables like $@ and $* simplify your logic. This guide covers:
- Positional parameters
- Grouping arguments
- Iterating with
"$@"vs"$*" - The impact of quoting
- Customizing the internal field separator (IFS)
- Compatibility considerations
1. Positional Parameters: $1, $2, …
By default, Bash assigns each argument to a numbered variable:
$@ and $* come in.
2. Grouping All Arguments: $@ vs $*
Both $@ and $* collect all positional arguments:

3. Iterating with a For Loop
Compare two scripts that loop over their arguments:
$@places each can in its own compartment.$*pours all the soda into one big bottle—individual cans are no longer separate.

4. The Importance of Double Quotes
Always quote
$@ and $*:"$@"expands each argument separately."$*"joins all arguments into a single string, separated by the first character ofIFS(default: space).
5. Modifying the Internal Field Separator (IFS)
You can changeIFS to alter how "$*" joins arguments:
6. Compatibility with Older Bash Versions
Some pre-4.0 Bash releases split unquoted assignments differently. For example, under Bash 3:7. Summary: $@ vs $*
| Variable | Quoted Expansion | Unquoted Expansion | Use Case |
|---|---|---|---|
$@ | Each arg is separate | Each word separate | Looping over arguments |
$* | All args as one | Splits on IFS | Passing all args to another command or function |
8. Conclusion
- Use
"$@"when you need to preserve each argument. - Use
"$*"to aggregate them into a single string with a custom delimiter. - Always quote both to maintain consistent behavior across Bash versions and avoid word-splitting pitfalls.
