How do I determine the number of positional parameters in a bash shell script?



  • Man page for bash - GNU Bourne-Again SHell

    The shell commands in a shell script.

    echo $#
    echo ${#*}
    echo ${#@}
    

    Results of running the script with the shell commands. All the shell commands return 15 positional parameters.

    $ ./positional_parameters If you see a faded sign at the side of the road that says ...
    15
    15
    15
    

    $# is commonly used in shell scripts to determine the number of positional parameters.

    The echo display of the positional parameter count is just used for demonstration, It would generally be used in a if statement or another test statement to test for the number of positional parameters.


Log in to reply
 

© Lightnetics 2024