我的bash脚本没有打印标记

时间:2016-05-20 07:45:04

标签: bash shell

我不确定我的bash脚本有什么问题,因为它没有打印给定的标志,也没有在case语句中回显它们:

 26 while getopts ":a:b:p:u" opts;
 27 do
 28   case $opts in
 29     a) echo got an A flag;;
 30     b) echo got an B flag;;
 31     u) user=$OPTARGS echo $user;;
 32     p) pass=$OPTARGS echo $pass;;
 33     ?) echo I don\'t know what flag is this;;
 34 esac
 35 done
 36 
 37 echo user: $user pass: $pass

这就是我所说的:

bash-4.3$ ./functionexample.sh -p 123 -u mona

2 个答案:

答案 0 :(得分:0)

由于IRC bash频道的帮助,我得到了修复:

26 while getopts ":a:b:p:u:" opts;
 27 do
 28   case $opts in
 29     a) echo got an A flag;;
 30     b) echo got an B flag;;
 31     u) user=$OPTARG; echo $user;;
 32     p) pass=$OPTARG; echo $pass;;
 33     ?) echo I don\'t know what flag is this;;
 34 esac
 35 done
 36 
 37 echo user: $user pass: $pass

答案 1 :(得分:0)

这应该有效:

Form