Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on option

Status
Not open for further replies.

vuakhobo

Technical User
Apr 22, 2004
41
US
I have this issue that I can't resolve and need help on.
Currently I can kick off the script 2 two ways:
with 4 args like:
scan_n_cktrl.sh F133 2 5 915
OR
scan_n_cktrl.sh -f F133 -r 2 -w 5 -t 915

But I can't combine 2 methods together to kick the scrip like this
scan_n_cktrl.sh F133 2 -w 5 -t 915
it seems like the option w and t doesn't work. Any idea why?

Here are my test code below:

FILENAME=$1
TIME_FILE=$2
while getopts ":w:t:" opt; do
case $opt in
w) WORKDAY=$OPTARG;;
t) TIME_FILE=$OPTARG;;
\?) show_usage ;;
esac
done
echo "$FILENAME and $TIME_TRL"
echo "WORKDAY:$WORKDAY"
echo "TIME_FILE=$TIME_FILE"


=== Result ====

+ getopts :w:t: opt
+ FILENAME=F133
+ TIME_TRL=2
+ echo F133 and 2
F133 and 2
+ echo WORKDAY:
WORKDAY:
+ echo TIME_FILE=
TIME_FILE=

 
Try:

at the end of your while loop, add:
Code:
shift $(($OPTIND - 1))

lose the "" around your aruments (just :wt not ":w:t:
 
it doesn't work kHz

#!/usr/bin/ksh
set -x
while getopts :w:t: opt; do
case $opt in
w) WORKDAY=$OPTARG;;
t) TIME_FILE=$OPTARG;;
\?) show_usage ;;
esac
shift $(($OPTIND - 1))
done

FILENAME=$1
TIME_TRL=$2
echo "$FILENAME and $TIME_TRL"
echo "WORKDAY:$WORKDAY"
echo "TIME_FILE=$TIME_FILE"

==Output===
pmart@satpai30:/vframe/STR/bin/Vinh>test.sh F133 2 -w 14 -t 915
+ getopts :w:t: opt
+ FILENAME=F133
+ TIME_TRL=2
+ echo F133 and 2
F133 and 2
+ echo WORKDAY:
WORKDAY:
+ echo TIME_FILE=
TIME_FILE=
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top