lundi 11 janvier 2016

bash - direct wrong flag input

I have a bash script that takes any of a bunch of flags. I want it to direct empty or wrong input (input that doesn't match any of the flags) to some show_help function. I've got the empty input part down, and when running the script with wrong flags I get the error for wrong input. But - when running with proper flags, I still get the error for wrong input :-(

I figure that something's wrong with my elif statement.. do I need to use commas between the values? something else?

Thanks.

The script:

...

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

Aucun commentaire:

Enregistrer un commentaire