shell programming: passing arguments to functions in

cal.sh

sh cal.sh 20 + 10 implement a function such parameter passing (shell is not a strict programming language, this parameter is not defined, direct reference function, the shell performs direct write)

#!/bin/bash
#

cal()

{
           case $2 in
                    +)
                        echo "`expr $1 + $3`"
                        ;;
                    -)
                        echo "`expr $1 - $3`"
                        ;;
                    \*)
                        echo "`expr $1 \* $3`"
                        ;;
                    /)
                        echo "`expr $1 / $3`"
                        ;;
            esac
}

 

 

Guess you like

Origin www.cnblogs.com/soymilk2019/p/11730021.html