Link Search Menu Expand Document

Functions

Table of contents

Function 1

#! /bin/bash 
myDate(){
    echo "today is: "
    date
    echo "have a great day!"
}

helloTo(){
    echo " hello $1 "
    echo " hello also to $2 "
    return 35
}

helloTo2(){
    echo " hello $newName "
}

echo "start here ..."

echo " *--------- 1st function helloTo ---------*"
myDate

echo " *--------- 2nd function helloTo ---------*"
helloTo "Mark" "John"
# helloTo $1 = Mark, $2 = John
echo "return value of the 2nd function is: $? "
# $? will output the above defined number 35, or anything string  

echo " *--------- 3rd function helloTo ---------*"
read -p "your name is ?  " newName
helloTo2
echo "end"

Function 2

#! /bin/bash 

helloTo(){
    echo " > hello $name "
    if [ $name == John ]; then
        return 30
        else 
            return 50
        # return can only come with integer
    fi
}

read -p "what is your name? " name

helloTo 
echo "$name is $? "

echo "end"