Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 直接错误标志输入_Bash_Shell_If Statement - Fatal编程技术网

Bash 直接错误标志输入

Bash 直接错误标志输入,bash,shell,if-statement,Bash,Shell,If Statement,我有一个bash脚本,它接受一堆标志中的任何一个。我希望它将空的或错误的输入(与任何标志都不匹配的输入)指向某个show_help函数。我已经将空输入部分关闭,当运行带有错误标志的脚本时,我会得到错误输入的错误。但是-当使用正确的标志运行时,我仍然会得到错误输入的错误 我觉得我的elif语句有问题。。值之间是否需要使用逗号?还有别的吗 剧本: f_read_input "$@" # direct wrong or empty flag input to show help if [ -z "$

我有一个bash脚本,它接受一堆标志中的任何一个。我希望它将空的或错误的输入(与任何标志都不匹配的输入)指向某个show_help函数。我已经将空输入部分关闭,当运行带有错误标志的脚本时,我会得到错误输入的错误。但是-当使用正确的标志运行时,我仍然会得到错误输入的错误

我觉得我的
elif
语句有问题。。值之间是否需要使用逗号?还有别的吗

剧本:

f_read_input "$@"

# direct wrong or empty flag input to show help
if [ -z "$@" ]; then
  echo "Please enter at least one flag (you entered none)."
  echo
  f_show_help
elif [ "$@" != $FLAG_HELP,$FLAG_TARLogs,$FLAG_TARResrc,$FLAG_DELLogs,$FLAG_TAREncod,$FLAG_DELResrc,$FLAG_DELEncod ]; then
  echo "One or more of the flags entered are wrong. Please check your spelling and see the list of flags below."
  echo
#  f_show_help
fi
显示功能包含选项及其使用方式

DisplayUsage()
{
 echo
 echo
 echo "Options are "
 echo 
 echo
 echo
 echo
}

使用getopts或getopt或case语句。是否无法将@$与值1或2或3(类似于@$!=value1或'2'或'3')进行比较?将选项保存在列表中,然后尝试使用此
[[[$list=~$@]]和&echo'yes'| echo'no'
yes表示正确选项否表示不正确
DisplayUsage()
{
 echo
 echo
 echo "Options are "
 echo 
 echo
 echo
 echo
}