#!/bin/bash
if [ vim /root/test.sh
#!/bin/bash
if [ $1 == "start" ]
then
echo "do start"
command groups
elif [ $1 == "stop" ]
then
echo "do stop"
command group
else
echo "Please make sure the positon variable is start or stop."
fi
#sh test.sh stop
$1取到了stop这个参数,接收来自命令行传入的参数,第一个参数用$1表示,第二个参数$2表示,。。。以此类推。
vim /root/test.sh
#!/bin/bash
for args in $@
do
echo $args
done
把上面这段代码录入保存为test.sh,授限可执行chmod +x test.sh:
#sh /root/test.sh arg1 arg2 arg3 arg4 xxx
输出参数:
arg1
arg3
arg4
xxx
这个例子中,我们用到了之“$@”,它代表了所有的命令行参数。
== "start" ]
then