This content originally appeared on DEV Community and was authored by AliMehraji
There is a say no difference between $@
and $*
in Shell! What ?!!
Have you ever thought if there is no difference, why there are two of them? it could be one $@
or $*
, Do You Agree?
So Let’s see What the difference is . Create a script and try it one by one
First One $@
:
#! /bin/bash
MAIN()
{
echo "First Parameter is $1"
}
MAIN $@
Execute it like below and give the script some arguments:
$ ./Diff.sh "Jhon Smith" "Marry Ann"
$ First Parameter is Jhon
Second One $*
:
#! /bin/bash
MAIN()
{
echo "First Parameter is $1"
}
MAIN $*
The result will be :
$ ./Diff.sh "Jhon Smith" "Marry Ann"
$ First Parameter is Jhon
Far Now There is no difference, maybe those people were right!
Let us go further and try them with double quotes "$@"
:
#! /bin/bash
MAIN()
{
echo "First Parameter is $1"
}
MAIN "$@"
$ ./Diff.sh "Jhon Smith" "Marry Ann"
$ First Parameter is Jhon Smith
The second one in double quotes "$*"
:
#! /bin/bash
MAIN()
{
echo "First Parameter is $1"
}
MAIN "$*"
$ ./Diff.sh "Jhon Smith" "Marry Ann"
$ First Parameter is Jhon Smith Marry Ann
So be careful when you use double quotes and tell those people there is a difference, explain to them shell is sensitive to double quotes.
Resources
This content originally appeared on DEV Community and was authored by AliMehraji

AliMehraji | Sciencx (2025-03-08T22:48:26+00:00) Special $@ and $* Parameters in bash. Retrieved from https://www.scien.cx/2025/03/08/special-and-parameters-in-bash/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.