The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
diff between tcsh and csh -f mahendrakamath UNIX for Dummies Questions & Answers 2 11-12-2007 04:19 AM
diff tungaw2004 UNIX for Dummies Questions & Answers 3 04-25-2007 07:54 AM
diff command gilead29 UNIX for Dummies Questions & Answers 7 03-09-2004 06:12 PM
diff 2 files; output diff's to 3rd file blt123 Shell Programming and Scripting 2 05-28-2002 08:29 AM
diff and ed? Brototype UNIX for Dummies Questions & Answers 2 10-29-2001 11:30 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-23-2006
Registered User
 

Join Date: Dec 2005
Posts: 25
Diff b/w $@ and $#

Hello,

Pls explain the difference between $# and $@, and how its used in shell scripting .

Thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 01-23-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
In short, RTFM.

Under Special Parameters in man sh
Code:
       @      Expands  to  the positional parameters, starting from one.  When
              the  expansion  occurs  within  double  quotes,  each  parameter
              expands to a separate word.  That is, "$@" is equivalent to "$1"
              "$2" ...  When there are no positional parameters, "$@"  and  $@
              expand to nothing (i.e., they are removed).
       #      Expands to the number of positional parameters in decimal.
Reply With Quote
  #3  
Old 01-23-2006
Registered User
 

Join Date: Dec 2005
Posts: 25
Thanks for the info, but its not clear to me can you explain me via an example......
Reply With Quote
  #4  
Old 01-24-2006
mona's Avatar
Registered User
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
An example to help you understand better.

$# - Will give you the number of arguments passed to the script
$@ - Will list all the arguments passed

Code:
/export/home/test/mons/UnixForum>cat test.sh
#!/bin/ksh
print "The number of arguments passed to this shell script is " $#

print "The arguments passed are as follows"
print "$@"
Code:
/export/home/test/mons/UnixForum>test.sh hai welcome to unixforum .com
The number of arguments passed to this shell script is  5
The arguments passed are as follows
hai welcome to unixforum .com
Reply With Quote
  #5  
Old 01-24-2006
Registered User
 

Join Date: Dec 2005
Posts: 25
Thanks for the expalantion ......
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0