微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux系统 shell脚本 接收用户的参数

 

1、基本shell脚本

#!/bin/bash
command

 

2、参数的变量

$0:脚本名称

$#:参数的数目

$*:参数

$1:第一个参数

$2:第二个参数

$3:第三个参数

$?:上一条命令执行成功输出0,否则其他数字。

[root@PC3 test]# cat a.sh
#!/bin/bash
echo "name: $0"
echo "number of args: $#"
echo "args: $*"
echo "1st arg: $1"
echo "4st arg: $4"
echo "2st arg: $2"
echo "the result of last command: $?"


[root@PC3 test]# bash a.sh one two three four five six name: a.sh number of args: 6 args: one two three four five six 1st arg: one 4st arg: four 2st arg: two the result of last command: 0

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。