Shell argument

I need to create a Kash script that will read two arguments. So if the user enters anything but 2 arguments then they will get and error message. If they enter the two arguments then it will print them out in reverse order. Does anyone know how i can do this?

if [ $# -eq 2 ]; then
        echo $2 $1
else
        echo "Please introduce 2 arguments"
fi

How would you also enter the script name after the arguments?

./script arg1 arg2

echo $0
 
$ cat arg.sh
#!/bin/ksh
[ $# -ne 2 ] && echo "Usage ${0} input1 input2 " && exit 1;
echo $2 $1
 
$ ./arg.sh 1 2
2 1
 
$ ./arg.sh
Usage ./arg.sh input1 input2
$

Sorry to be a pain again scripter.online.
The trailing semicolon is not needed and can cause some shells to misbehave.
In this context it is harmless.
I'm only being pedantic because you are building a useful resource.

#!/bin/ksh
[ $# -ne 2 ] && echo "Usage ${0} input1 input2 " && exit 1;
echo $2 $1

Personally I might use "&&" to test the success of a command when writing a dependent cron, but rarely in scripts.
However in Oracle scripting the semicolon is critical.

ohh
thanks methyl :slight_smile:
I am not effected upto now ......thatwhy i dont know :smiley: