'Bash argument with multiple values
My situation is the following: I want the script to be able to be able to receive multiple value parameters. For an example
./script.sh -u username -p password -h hostname -pk file1.zip file2.zip
The way it is made it can receive only one file as an argument e.g ./script -pk file1.zip
I'm not sure how make it so $PACKAGE variable can receive multiple values. Not a pro on bash, so would appreciate some ideas :)
while [ "$1" != "" ]; do
case $1 in
-h | --host ) shift
HOST=$1 ;;
-u | --username ) shift
USER=$1 ;;
-p | --password ) shift
PASSWORD=$1 ;;
-o | --out ) shift
OUT=$1 ;;
-pk | --package ) shift
PACKAGE=$1 ;;
-g | --group ) shift
GROUP=$1 ;;
-n | --name ) shift
NAME=$1 ;;
-h | --help ) help
exit
;;
list ) ACTION="list"
;;
"install" ) ACTION="install"
;;
"upload-install") ACTION="upload-install"
;;
upload ) ACTION="upload"
;;
download ) ACTION="download"
;;
delete ) ACTION="delete"
;;
* ) usage exit 1
esac
shift
done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
