Anirudha
Anirudha

Reputation: 32787

How to call a function with parameter in Shell

I have defined a function that takes a parameter

function expandSession()
{
    line=$1;
....
}

How can I call this function with a parameter?

I tried:

expandSession $line;

Giving error as

expandSession: command not found

Full code:

if [ ! -z "$HOMESERVER" ] ; then
....
                while [[ "$START_DATE" -le "$END_DATE" ]];
                do
                        zgrep ...; do
                            expandSession $line; <------
                        done
                        grep -e ...; do
                            expandSession $line; <------
                        done
                        let START_DATE+=86400;
                done
fi
expandSession ()
{
    line=$1;

}

Upvotes: 0

Views: 180

Answers (1)

l0b0
l0b0

Reputation: 58768

@BlueMoon is on the right track: the function is not in scope. A common error is to ignore the evaluation sequence, and place a function definition after the call to it.

Upvotes: 2

Related Questions