linux中shell变量$#,$@,$0,$1,$2的含义是什么

本篇内容介绍了“linux中shell变量$#,$@,$0,$1,$2的含义是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

10余年的云浮网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都营销网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整云浮建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“云浮网站设计”,“云浮网站推广”以来,每个客户项目都认真落实执行。

变量说明: 
$$ 
Shell本身的PID(ProcessID) 
$! 
Shell最后运行的后台Process的PID 
$? 
最后运行的命令的结束代码(返回值) 
$- 
使用Set命令设定的Flag一览 
$* 
所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 
$@ 
所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。 
$# 
添加到Shell的参数个数 
$0 
Shell本身的文件名 
$1~$n 
添加到Shell的各参数值。$1是第1参数、$2是第2参数…。

test.sh 内容如下:

#!/bin/bash
printf "The string is %s\n" "$$"
printf "The string is %s\n" "$!"
printf "The string is %s\n" "$?"
printf "The string is %s\n" "$*"
printf "The string is %s\n" "$@"
printf "The string is %s\n" "$#"
printf "The string is %s\n" "$0"
printf "The string is %s\n" "$1"
printf "The string is %s\n" "$2"
[root@cz_fbsdb500_06 ]# sh test.sh Im so diao 
The string is 6169
The string is 
The string is 0
The string is Im so diao
The string is Im
The string is so
The string is diao
The string is 3
The string is test.sh
The string is Im
The string is so

“linux中shell变量$#,$@,$0,$1,$2的含义是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!

文章题目:linux中shell变量$#,$@,$0,$1,$2的含义是什么
URL链接:https://www.cdcxhl.com/article46/iedgeg.html

成都网站建设公司_创新互联,为您提供响应式网站网站改版网站导航商城网站云服务器小程序开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都app开发公司