How to call a function in Shell..?

#!/bin/bash

FUN_ECHO(){
echo $1
}

FUN_ECHO "hi how are you ?" 

This code will work fine.

BUT is it possible to make the following to work ?

FUN_ECHO "hi how are you ?" 

FUN_ECHO(){
echo $1
}

I know that the code will be executed line by line. But i have a number of functions.. which may call another function and may return to some other... and so and so...

is there any way to call as in Java...?? [ i mean from anywhere in the same page/script]

No: Functions

1 Like

Define all your functions at the beginning of the script. Then they may be called from wherever you like, in any order, including from another function.

a1()
{
 echo "$FUNCNAME"
 a3
}

a2()
{
 echo "$FUNCNAME"
}

a3()
{
 echo "$FUNCNAME"
 a2
}

a1
1 Like

Thank you cfajohnson..

i tried this method.
Its works fine.

thanks again..

You could also collect your functions in a separate file, and use them in other scripts as well. Include them in your script like this:

. func_library.sh

The dot command runs the func_library.sh script in the same shell, thus making the functions available to it. Less clutter and one place to maintain commonly used functions.

1 Like

Oh yes. I found it somewhere while Googling.

But in my case , i want to use this in Only in one file.

The thing is i am creating an SVN patch maker. And i want the entire patch maker as only one shell file.

Its done.

Thanks.