Hi,
My environement
OS: Linux Fedora Core 17 X86_64
KSH version: sh (AT&T Research) 93u+ 2012-08-01
As I understand inside a Kornshell script, the getopts statement allows to collect information about the switches provided for the script (if any). Besides, it is possible to enable/disable those switches respectively by preceding each switch letter with either - or +.
I just wanted to see this in pratice. Therefore I wrote the following code which unfortunately does not give the expected output.
#!/usr/bin/ksh
while getopts :xy arguments
do
case $arguments in
x)
print "x on"
;;
+x)
print "x off"
;;
y)
print "y on"
;;
+y)
print "y off"
;;
\?)
print "unknown switch"
;;
esac
done
And here is what I get when I run the above script in my linux terminal (myscript.ksh is the name of my script)
$ ./myscript.ksh -x
x on
$ ./myscript.ksh +x
$ ./myscript.ksh -y
y on
$ ./myscript.ksh +y
$
As you can see whenever a switch is preceded by - (therefore enabled) the script prints the corresponding message but whenever it is preceded by the + (disabled) the scripts doesn't seem to do anything and there is no message printed.
Could you kindly help me understand the problem in my script?
Thanks in advance,