The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 07:19 AM
diff tungaw2004 UNIX for Dummies Questions & Answers 3 04-25-2007 10:54 AM
diff command gilead29 UNIX for Dummies Questions & Answers 7 03-09-2004 09:12 PM
diff 2 files; output diff's to 3rd file blt123 Shell Programming and Scripting 2 05-28-2002 11:29 AM
diff and ed? Brototype UNIX for Dummies Questions & Answers 2 10-29-2001 02:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-24-2006
PradeepRed PradeepRed is offline
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
  #2 (permalink)  
Old 01-24-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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.
  #3 (permalink)  
Old 01-24-2006
PradeepRed PradeepRed is offline
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......
  #4 (permalink)  
Old 01-24-2006
mona's Avatar
mona mona is offline
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
  #5 (permalink)  
Old 01-24-2006
PradeepRed PradeepRed is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 25
Thanks for the expalantion ......
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0