How do i use positional parameters in a bash shell script?



  • These are positional parameters.

    $0, $1, $2, $3, $4, $5, $6, $7, $8, and $9

    $0 is the name of the script, $1 - S9 are positional parameters to the script.

    echo $0
    echo $1
    echo $2
    echo $3
    

    Even if the positional parameter is blank, it prints and empty line.

    $ ./params.sh
    ./params.sh
    
    
    

    With parameters the output is:

    $ ./params.sh one two three
    ./params.sh
    one
    two
    three
    

    Just echoing the positional parameters is useful in some cases but, they are mostly used in combination with conditional statements and tests.


Log in to reply
 

© Lightnetics 2024