bash command line args


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. while true; do
  2. case "$1" in
  3. -h|--help|-\?) show_help; exit 0;;
  4. -v|--verbose) verbose=1; shift;;
  5. -a) if [ $# -gt 1 ]; then
  6. UNAME=$2; shift 2
  7. else
  8. echo "-a requires an argument" 1>&2
  9. exit 1
  10. fi ;;
  11. --) shift; break;;
  12. -*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
  13. *) break;;
  14. esac
  15. done

URL: http://mywiki.wooledge.org/BashFAQ#BashFAQ.2BAC8-035.How_can_I_handle_command-line_arguments_.28options.29_to_my_script_easily.3F

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.