1

Say I have this function:

function run_sanity_check(){
   echo -e "This is test level 1\n"
   echo -e "This is test level 2\n"
}

and this other function:

function run_test(){
  ... environment setup routine runs here
  echo -e "Running tests...\n"

  run_sanity_check --> this would be my call for the function above
}

When I call "run_test" I get this error: function: not found

Any help is appreciated.

1
  • 1
    I think you want either the parens or the function keyword but not both. Your problem is not with the invocation it's with the definition. See tldp.org/LDP/abs/html/functions.html Commented Feb 25, 2016 at 3:50

1 Answer 1

4

As Brian's comment mentions, you need to use either function or () but not both.

Both of the following are valid, based on the documentation.

function run_sanity_check{
   echo -e "This is test level 1\n"
   echo -e "This is test level 2\n"
}


run_sanity_check(){
   echo -e "This is test level 1\n"
   echo -e "This is test level 2\n"
}

The following script prints expected output.

run_sanity_check(){
   echo -e "This is test level 1\n"
   echo -e "This is test level 2\n"
}

run_test(){
  echo -e "Running tests...\n"

  run_sanity_check 
}

run_test
Sign up to request clarification or add additional context in comments.

5 Comments

I removed the "function" keyword and now it completely ignores the inner function call.
@leofelipe, Did you remove it from both?
@ merlin2011, Yes, I did.
@leofelipe, I just posted a fully working script. It may be that something else is breaking with your script that you're not showing.
Yup, I tested here too and your script works just fine. Let me look further into the script and try to figure out what is going on. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.