Skip to content

Instantly share code, notes, and snippets.

@joariasl
Last active January 6, 2016 17:46
Show Gist options
  • Save joariasl/a94dc3fdd86e78ed8899 to your computer and use it in GitHub Desktop.
Save joariasl/a94dc3fdd86e78ed8899 to your computer and use it in GitHub Desktop.
Bash command line arguments parse
#!/bin/bash
showUsage() {
echo "Usage:
Usage instruction..."
}
if (( ${#@} == 0 )); then
showUsage
exit 1
fi
while [ "$1" != "" ]; do
case $1 in
-f | --file )
shift
filename=$1
;;
-i | --interactive )
interactive=1
;;
-h | --help )
showUsage
exit 0
;;
* )
showUsage
exit 1
;;
esac
shift
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment