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

Is scripting and coding the same thing?

947


How to set an array in linux?

1140


What is computer cli?

852


What is the use of break command?

1051


What is bash command used for?

1018


Write a shell script to get current date, time, user name and current working directory.

1039


Explore about environment variables?

993


What is shell application?

956


What is the crontab?

1020


What are the 3 standard streams in linux?

1064


c program to display the information of given file similar to givan by the unix or linux command ls -l

2166


Write a command sequence to find all the files modified in less than 2 days and print the record count of each.

1453


Write a script to print the first 10 elements of fibonacci series.

2290


What is the use of echo in shell script?

970


how to get part of string variable with echo command only?

982