How do i pass parameters to a function in a bash shell script?



  • Also see: How do i use functions in bash shell scripts?

    The purpose is to show the use of parameters in functions, rather than demonstrate a usable script.

    Here we have the code in a script. As with regular scripts, the use of $1, $2, etc can be used.

    fruit_show() {
    echo "echo "On the central display at the show today are $1 and $2."
    }
    
    fruit_show apples oranges
    

    Line number 5 shows the function being executed with two parameters, apples and oranges.

    Running the script.
    $ ./functionparms.sh
    echo "On the central display at the show today are apples and oranges."


Log in to reply
 

© Lightnetics 2019