Skip to content

Instantly share code, notes, and snippets.

@yuraloginoff
Last active June 6, 2020 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuraloginoff/905696cdd85341dea399cc94c687643f to your computer and use it in GitHub Desktop.
Save yuraloginoff/905696cdd85341dea399cc94c687643f to your computer and use it in GitHub Desktop.
#bash: Check for cli arguments
#!/bin/bash
# Exit if no arguments
[ $# -eq 0 ] && { echo "Usage: $0 param name"; exit 1; }
# if no command line arg given
# set var to Unknown
if [ -z $1 ]
then
var="Unknown"
elif [ -n $1 ]
then
# otherwise make first arg as a var
var=$1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment