xGen
xGen

Reputation: 554

Unable to read korn shell Parameter

Gone through few Posts in SO like this one but unable to resolve the issue. I am passing 4 arguments to a korn shell script. But it doesnt read the 4th arg. Here is the code

#Get Input parameters

while getopts ":s:e:n:d" OPT
do
   case $OPT in
      (s) from=$OPTARG;;
      (e) to=$OPTARG;;
      (n) process=$OPTARG;;
      (d) path=$OPTARG;;
      (\?) printerror;;
   esac
done
print "from $from" 1>&2;
print "to $to" 1>&2;
print "process $process" 1>&2;
print "path $path" 1>&2;

Then i execute the script like this

loaddat.ksh -s 1234 -e 1234 -n 1 -d /d/asa/

whatever i do path value does not get printed. Tried with and without quotes. even just as a string like xyz as value.

Upvotes: 0

Views: 197

Answers (1)

ramana_k
ramana_k

Reputation: 1933

In the option string, You need a colon after d

":s:e:n:d:"

because in the command line, option '-d' is expected to be followed by its value, which in this case is a path.

If the option letter in the string 'd' is not followed by ':', getopts won't check for its value.

Upvotes: 2

Related Questions