How to create & use functions in shell scripts. How to pass parameters to a function and use it, using return values.

866    Asked by TanuBakshi in Devops , Asked on Feb 2, 2020
Answered by Tanu Bakshi

Many times it becomes necessary to pass arguments in functions. These arguments can be taken from the user during runtime or can be passed on via environment variables etc.

Syntax -

$ function_name $arg1 $arg2





Example -

    mytestfunc()

  {

  c = $1+$2

  }

 To return values within function.

 function_name()

 {

 echo “testing return”

 return 1

 }



Your Answer

Interviews

Parent Categories