Passing parameters of shell script

1. Primary transfer

[root@hya srcipts]# vim 传参方式1.sh
#!/bin/bash
echo $1 $2 $3
[root@hya srcipts]# ./传参方式1.sh 1 2 3
1 2 3

2. Advanced Part

[root@hya srcipts]# vim 传参方式高级篇2.sh
#!/bin/bash
while getopts "s:p:" opt
do
  case $opt in
            s)
              save=$OPTARG;;
            p)
              path=$OPTARG;;
            ?)
              echo "参数输入错误"
             exit 1;;
 esac
done
echo $save
echo $path


[root@hya srcipts]# ./传参方式高级篇2.sh -s hya -p hhh 
hya
hhh

 

Guess you like

Origin blog.csdn.net/yeyslspi59/article/details/108110717