Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How do I run a script from command prompt?

997


Print the 10th line without using tail and head command.

2110


Please give me example of " at command , contrab command " how to use

2721


What are the different commands available to check the disk usage?

920


Explore about environment variables?

980


How to print all array elements and their respective indexes?

900


What is the use of .sh file?

1052


How can you find out how long the system has been running?

845


In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?

1069


What is shell variable?

862


What exactly is a shell?

1014


Is shell and terminal the same?

993


What is gui scripting?

1018


What is a shell made of?

905


What is a shell in operating system?

1034