The meaning of $and the difference between $and $@ in shell
Today, the editor shares with you the meaning of $in shell and the difference between $and $@. I believe most people don't know much about it. In order to make you understand better, the editor summed up the following content for you. Without saying much, let's read on.
#! / bin/bash#Author:Sparrow#Name:explain_shell_parameters#Date 2020-3-11#Description:#Explain what $0 $1 $2 $3 $4 $@ $* $# mean#Program begin#Ensure enter six parameters at leastif [$#-le 6]; then echo "Please enter 6 parameters at least!" Exit 1fi#Echo every $echo "\ $0-$0" echo "\ $1-$1" echo "\ $2-$2" echo "\ $3-$3" echo "\ $4-$4" echo "\ $5-$5" echo "\ $6- -$6 "echo"\ $7-$7 "echo"\ $8-$8 "echo"\ $#-$# "echo"\ $@-$@ "echo"\ $*-$* "echo"\ $? "l output the result sh Explain_shell_parameters.sh 1 2 3 4 5 6 7 "result # $0 is the script name $0-explain_shell_parameters.sh $1-1 $2-2 $3-3 $4-4 $5-5 $6- 6 $7-7 $8 $#-8 $@-1 2 3 4 5 6 7 8 $*-1 2 3 4 5 6 6 7 7 the difference between $?-0 $* and $@ when $* And $@ are not surrounded by double quotes "" There is no difference between them, each parameter received is treated as a piece of data, separated by spaces from each other. But when they are enclosed in double quotes, there is a difference: "$*" treats all parameters as a piece of data as a whole, rather than each parameter as a piece of data. "$@" still treats each parameter as a piece of data, independent of each other. For example, if five parameters are passed, for "$*", the five parameters will be merged together to form a piece of data, which can not be separated; for "$@", the five parameters are independent of each other. They are five pieces of data. If you use echo to output "$*" and "$@" directly, you can't see the difference; but if you use a for loop to output data one by one, you can immediately see the difference.
So much for the meaning of $in shell and the difference between $@ and $@. I hope the above content can be helpful to you and learn more. If you like this article, you might as well share it for more people to see.