Reputation: 3893
I have found '$#' statement at the very beginning of utility ksh script but i was unable to found any info about what does '$#' means. Usage:
if [[ $# -ne 1 ]];then
LogMessage "Usage:\nJavaWSJBossInstall! war_file"
exit
fi
Can anyone explain what does it mean? Thanks a lot.
Upvotes: 1
Views: 1074
Reputation: 25337
The variable #
contains the number of arguments passed to the script. if you call you script like this:
script foo bar
then $#
will give the you value 2
.
Upvotes: 0
Reputation: 44354
See man ksh
. $#
gives the number of command-line parameters. The if
statement could also be written as:
if (( $# != 1 ));
Upvotes: 0
Reputation: 12755
$# denotes the number of command line arguments supplied to the script. In your case it is checked whether exactly one argument was passed to it, otherwise some string explaining the usage is printed.
Upvotes: 1
Reputation: 18960
The shell variable #
is the number of arguments to your script. You can access them as $1
, $2
and so on.
Upvotes: 3
Reputation: 272517
It evaluates to the number of command-line arguments passed to the script.
The best place to look to discover this kind of thing is the Bash manual. And in this particular case, you're interested in the section on special parameters.
(oops, this is ksh, not Bash).
Upvotes: 1