Hi,
I am not very skilled using ksh scripts.
How do I create a ksh script that will accept arguments and use them in the script ?
I need to make this:
Run this command with this argument:
./mykshprogram.ksh madsen
and sometimes I need to do this:
Run the ksh again with 2 arguments:
./mykshprogram.ksh madsen jensen
So I need something like this:
if argument 2 is empty
do
/usr/tools/run.exe -i madsen
else
/usr/tools/run2.exe -i madsen -y jensen
Thanks in advance
Maybe:
if [ $# -lt 2 ]
then
/usr/tools/run.exe -i $1
else
/usr/tools/run2.exe -i $1 -y $2
fi
ieth0
September 30, 2011, 8:39am
3
if [ -z $* ];then
/usr/tools/run.exe -i madsen
elif [[ -n $1 && -z $2 ]];then
/usr/tools/run2.exe -i $1
elif [[ -n $1 && -n $2 ]];then
/usr/tools/run2.exe -i $1 -y $2
fi
edit: i thought you said if all args were empty , thats why i added 1st if.
gary_w
September 30, 2011, 10:14am
4
For more robust command line argument processing, read up on the "getopts" program for parsing command line options. Here is one example I found that addresses this:
KSH - Sample program - Scroll down a few examples to see the example that uses getopts.
Gary