Skip to content

Instantly share code, notes, and snippets.

@wwwins
Created April 23, 2020 07:20
Show Gist options
  • Save wwwins/6070a8fd791dba600e135dd404d42797 to your computer and use it in GitHub Desktop.
Save wwwins/6070a8fd791dba600e135dd404d42797 to your computer and use it in GitHub Desktop.
Get shell script arguments
#!/bin/sh
usage()
{
echo ""
echo "Usage: $0 -n project-name -o project-owner -p port -t [init|update]"
echo "\t-n project name"
echo "\t-o project owner"
echo "\t-p port"
echo "\t-t init or update"
exit 1
}
while getopts "n:o:p:t:" opt
do
case "$opt" in
n ) name="$OPTARG" ;;
o ) owner="$OPTARG" ;;
p ) port="$OPTARG" ;;
t ) action="$OPTARG" ;;
? ) usage ;;
esac
done
# Print usage in case parameters are empty
if [ -z "$name" ] || [ -z "$owner" ] || [ -z "$port" ] || [ -z "$action" ]
then
echo "Invalid options";
usage
fi
# Begin script in case all parameters are correct
echo "$name"
echo "$owner"
echo "$port"
echo "$action"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment