Scripting Question:

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 25, 2005 at 11:45:25AM -0600, Dawes, Stephen wrote:
> Can someone tell me how to determine how many parameters are passed to a
> script when the script is called?
> 
> For example a simple script called trythis:
> #!/bin/bash
> 
> Echo -e $0
> 
> And when you call the script:
> trythis 1 2 3 4 5
> 
> I get the output 
> trythis
> 
> What I want to see is that 5 parameters were passed to the script.
> 
> Any suggestions?
> 
> Steve Dawes
> Phone: (403) 268-5527
> Email: SDawes at calgary.ca

Try using '$#'.  For example:

echo $#

Other special variables produced and used by bash include $? (last
program exit error status), $$ (current process number), and $* (all
of the command line parameters).  There might be others that do not
come to mind at this moment--see the bash man page for more info.

HTH, and have a _great_ day!

-- 
Ralph.  N6BNO.  Wisdom comes from central processing, not from I/O.
rreid at sunset.net  http://personalweb.sunset.net/~rreid
...passing through The City of Internet at the speed of light!
_PI = 4 * ARCTAN (1)




[Index of Archives]     [Linux for the Blind]     [Fedora Discussioin]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]
  Powered by Linux