I have some understanding that to check the number of arguments being passed into the shell script all I have to do inside the shell script is this: Example 1

if [ "$#" -ne 2 ]; then
   do something;

However, I am a little confused and would like to know whether the name of the shell script when being run is considered part of the arguments as well as this is the case for python script when it comes to sys.argv.

An example in the terminal would be like: Example 2

./script.sh $1 $2

In this case for Example 2 how many arguments would actually be considered to be passed in to Example 1 if else loop.

  • 1
    What result did you get when you tested it? Commented Jan 10, 2019 at 11:25

1 Answer 1


The name of the script is not considered as part of the positional parameters. This means that

somescript arg1 arg2

will set $1 to arg1 and $2 to arg2 and that $# will be 2.

The name of the script will be available in $0, but $0 is special in that it's not included in the array $@, and $# is the length (number of elements) of $@.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .