How do you read arguments in a shell program - $1, $2 ..?
Answer Posted / pitambar mishra
### Script for greater between 2 numbers
### name : greater_of_2_numbers.ksh
#! /bin/ksh
### If you won't supply 2 numbers then it will prompt you to 2 numbers. ###
if [ $# -ne 2 ] ($# : number of positional parameters)
then
echo "Usage: $0 <Enter 2 numbers>" ($0 : name of script)
exit 1
fi
### main script
if [ $1 -gt $2 ] ($1 and $2 : Two positional parameters)
then
echo "$1 is greater than $2"
elif [ $2 -gt $1 ]
then
echo "$2 is greater than $1"
else
echo "Two numbers are equal"
fi
To execute :
ksh greater_of_2_numbers.ksh 5 4
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is shift command in shell script?
How to get script name inside a script?
Can shell script run on windows?
What language is bash written in?
What exactly is a shell?
Is powershell a language?
What is meant by $1 in shell script?
I want to connect to a remote server and execute some commands, how can I achieve this?
How can you get the value of pi till a 100 decimal places?
What is a program shell?
Why do we write bin bash in shell scripts?
How do I run a shell script in powershell?
What is k shell?
Why is shell scripting important?
c program the catches the ctrl-c(SIGINT) Signal for the first time and prints a output rather and exit on pressing Ctrl-C again