TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
@ symbol in Bash is a special parameter and array subscript that expands to all positional parameters or all elements of an array. Its primary mechanical function is to handle multi-word arguments and array elements, treating each expanded element as a discrete, individual word when evaluated in contexts subject to word splitting.
Positional Parameters Expansion
When used as a standalone special parameter,@ references the arguments passed to the current shell or function. Its behavior is strictly dictated by whether it is enclosed in double quotes and the evaluation context.
- Unquoted (
$@): Expands to all positional parameters starting from$1. The shell subsequently subjects the expanded result to word splitting (based onIFS) and pathname expansion (globbing). - Double-quoted (
"$@"): In contexts where word splitting is performed (such as command arguments), it expands each positional parameter into a separate, distinct word, bypassing word splitting and pathname expansion. Mechanically, it is equivalent to"$1" "$2" ... "$N". However, in contexts where word splitting is not performed (such as scalar variable assignments likevar="$@"or inside[[ ]]conditional tests),"$@"does not expand into separate words. Instead, it flattens the elements into a single string separated by a space, regardless of the value ofIFS.
Array Element Expansion
When applied as a subscript within curly braces,@ targets the elements of an array.
- Unquoted (
${array_name[@]}): Expands all values in an indexed or associative array, subject to standard word splitting and globbing. - Double-quoted (
"${array_name[@]}"): Expands each array element as a separate word (in word-splitting contexts), preserving the exact string boundaries of each element as they were originally assigned.
Array Key/Index Expansion
By prepending the parameter name with the! operator inside the curly braces, @ evaluates to the indices (for indexed arrays) or keys (for associative arrays) rather than the values.
Element Counting
When combined with the# length operator, @ returns the total number of elements rather than the elements themselves.
Parameter Slicing
The@ operator supports offset and length expansion to extract a contiguous subset of elements.
length elements starting from the specified offset. If length is omitted, it expands to all elements from the offset to the end of the array or positional parameters.
Pattern Substitution
The@ operator allows search and replace operations to be mapped across all elements of an array or all positional parameters simultaneously.
Technical Distinction: @ vs *
The @ operator is frequently contrasted with the * operator. Their mechanical differences are exposed during double-quoted expansion and when handling empty parameter lists:
- Empty Parameters: If there are zero positional parameters (or when an array is empty),
"$@"expands to nothing (zero words). In contrast,"$*"expands to a single empty string (one word). - Delimiters and Non-Word-Splitting Contexts: In contexts where word splitting is performed,
"$@"consistently maintains the original token boundaries and discrete element separation regardless of theIFSstate. In contexts where word splitting is not performed,"$@"flattens elements using a space as the delimiter, whereas"$*"flattens elements using the first character ofIFS.
Master Bash with Deep Grasping Methodology!Learn More





