what does $#,$* means

:slight_smile: Hi,

In some script i got these regular expression

like ,
n=$#
and
for i in $*

can anybody let me know, what does it means

$#-no of arguments
$*-the arguments
write below in a test file

echo $#
echo $*

run that as

test 1 2 3 4

o/p will be

4
1 2 3 4

hope you got it.. google it you will get lot of answers:)

from Chapter 9 of the Advanced Bash Scripting Guide - bash internal variables

thanks ..... :slight_smile:

Thank You Yogesh for the link. Good piece of information there in that link.

Basically, there are two ways of reading inputs:
Type 01: Command Line
Type 02: Interactive way
Your problem is pertaining to the Type 01: this is method is used when we do not know the numbers of arguments that are present in the command line prompt. For this shell uses positional parameters like $0, $, $#, $?, etc .
E.g. 01:
echo �The Number of Arguments: $#�
echo �The List of Arguments�
for i in $

do
echo $i
done

E.g. 02:
echo �The Number of Arguments: $#�
echo �The List of Arguments�
for i
do
echo $i
done

In the Type 02 method usually we are reading the inputs through read construct of shell and print the variable using for loop as fallows:
E.g. 01
echo �Enter the argument1�
read a
echo �Enter the argument2�
read b
for i in $a $b
do
echo $i
done