GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Shell Scripting
Go To First  |  Previous Question  |  Next Question 
 Shell Scripting  |  Question 3 of 47    Print  
How do you read arguments in a shell program - $1, $2 ?

  
Total Answers and Comments: 5 Last Update: May 31, 2007   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Muthu
 
#!/bin/sh 
for i in $* 
do 
echo $i 
done 
 
On executig the above script with any number of command-line arguments it will display all the parametsrs.

Above answer was rated as good by the following members:
balaksara, sesethi, pmchaurasia, kavinithas
June 02, 2005 07:25:16   #1  
Muthu        

RE: How do you read arguments in a shell program - $1, $2 ?
#!/bin/sh
for i in $*
do
echo $i
done

On executig the above script with any number of command-line arguments it will display all the parametsrs.

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 1Overall Rating: +1    
June 03, 2005 12:47:02   #2  
joadavis        

RE: How do you read arguments in a shell program - $1, $2 ?
$1 would be the first command line argument $2 the second and so on
$0 is the name of the script or function

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 05, 2005 01:00:49   #3  
abhay        

RE: How do you read arguments in a shell program - $1, $2 ?
Shell script accepts parameters in following format...
$1 : first
$2 : second....so on upto
$9 : 9th param
whereas $0 : gives script/function name
If your script has more than 9 params then accept in following way...
${12} : 12th param
${18} : 18th param

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
February 21, 2007 02:33:33   #4  
Tuku        

RE: How do you read arguments in a shell program - $1,...
U can also use Shift for getting the behind 9th parameters.........
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 2Overall Rating: -2    
May 31, 2007 05:28:36   #5  
vaibhavjain85 Member Since: May 2007   Contribution: 2    

RE: How do you read arguments in a shell program - $1,...
by using :

exec<$1 or exec<$2

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape