Skip to content

Instantly share code, notes, and snippets.

@s1ntoneli
Created October 12, 2018 12:57
Show Gist options
  • Select an option

  • Save s1ntoneli/fcd49d473cc4481453a5d5429ea2d751 to your computer and use it in GitHub Desktop.

Select an option

Save s1ntoneli/fcd49d473cc4481453a5d5429ea2d751 to your computer and use it in GitHub Desktop.
shell getopt sample
#!/bin/bash
TEMP=`getopt -o u:p: --long user:,passwd: -n "$0" -- "$@"`
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
eval set -- "$TEMP"
while true; do
case "$1" in
-u|--user) echo "User: $2"; shift 2 ;;
-p|--passwd) echo "Password: $2"; shift 2 ;;
--) shift; break ;;
esac
done
echo "Remaining arguments:"
for arg do
echo '--> '"\`$arg'" ;
done
~
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment