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

 

posted @ 2021-04-21 18:10  小鲨鱼2018  阅读(714)  评论(0编辑  收藏  举报