Created
April 23, 2020 07:20
-
-
Save wwwins/6070a8fd791dba600e135dd404d42797 to your computer and use it in GitHub Desktop.
Get shell script arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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