Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The meaning of $and the difference between $and $@ in shell

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report