0

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;

}
Anirudha
  • 32,393
  • 7
  • 68
  • 89
  • possible duplicate of [Passing parameters to a bash function](http://stackoverflow.com/questions/6212219/passing-parameters-to-a-bash-function) – Aakash Jain Nov 28 '14 at 09:12
  • 2
    Your function definition and call is correct. What the error message says is that there's no `expandSession` command or function defined when you call it. Check the spelling, check if it's been really defined etc. – P.P Nov 28 '14 at 09:13

1 Answers1

2

@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.

l0b0
  • 55,365
  • 30
  • 138
  • 223