How to pass variable from one function to another function?

updateEnvironmentField() {
	
	      linewithoutquotes=`echo $LINE | tr -d '"'`
             b()
}


I want to pass variable named $linewithoutquotes to another method called b(), which is called from updateEnvironmentField() method. How to do the above requirement with shell script

1 Like

First: you definitely shouldn't use backticks any more and the use of echo ... | tr ... is overly complicated. You can do:

linewithoutquotes="${LINE//\"/}"

To pass it to another function pass it as an argument:

b ()
{
     passedline="$1"
     echo "inside b(), passed line is: $passedline"
}


updateEnvironmentField()
{
     linewithoutquotes="${LINE//\"/}" 
     b "$linewithoutquotes"
}

I hope this helps.

bakunin

2 Likes