[SOLVED] Bash script passing variable and values
by GPGAgent from LinuxQuestions.org on (#53JYJ)
I know I can use getopts to provide options and values to a script
Code:makereport -u jsmith -p notebooks -d 10-20-2011 -f pdfand in the script you do this:
Code:while getopts u:d:p:f: option
do
case "${option}"
in
u) USER=${OPTARG};;
d) DATE=${OPTARG};;
p) PRODUCT=${OPTARG};;
f) FORMAT=${OPTARG};;
esac
doneWhat I would like to do is this:
Code:makereport USER=jsmith PRODUCT="note books" DATE=10-20-2011 FORMAT=pdfand then in the script I have immediate access to the variables, for example, in the script:
Code:echo "User: $USER | Product: $PRODUCT"Would produce:
Code:User: jsmith | Product: note booksAlso I would like the order of the parameters to not matter.
I'm think I'll need to test $1, $2, $3 etc and go from there.
Any clever methods out there?


Code:makereport -u jsmith -p notebooks -d 10-20-2011 -f pdfand in the script you do this:
Code:while getopts u:d:p:f: option
do
case "${option}"
in
u) USER=${OPTARG};;
d) DATE=${OPTARG};;
p) PRODUCT=${OPTARG};;
f) FORMAT=${OPTARG};;
esac
doneWhat I would like to do is this:
Code:makereport USER=jsmith PRODUCT="note books" DATE=10-20-2011 FORMAT=pdfand then in the script I have immediate access to the variables, for example, in the script:
Code:echo "User: $USER | Product: $PRODUCT"Would produce:
Code:User: jsmith | Product: note booksAlso I would like the order of the parameters to not matter.
I'm think I'll need to test $1, $2, $3 etc and go from there.
Any clever methods out there?