Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

So here I have a simple function that I wish to debug. However, I am unable to debug the desired function even with set -o functrace enabled. Before resorting to asking this question, I had managed to find a possible solution that did not produce the desired results, which is located here.

How can I get bash debug my functions?

#!/bin/bash
echo "Hello World"
hello() {
    echo "Hello world"
}

output:

user@mac11:53:29~/desktop bash -x debug.sh 
+ echo 'Hello World'
Hello World
user@mac11:54:55~/desktop 
share|improve this question
1  
In the example code, function hello is never called. –  demure Jun 9 '13 at 16:47
add comment

closed as too localized by manatwork, Anthon, Mat, jasonwryan, vonbrand Jun 9 '13 at 19:47

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 2 down vote accepted

but that answer in the link does seem to work ........

  Kaizen ~/so_test $ cat zhello.sh
  set -x ;
  set -o functrace

  hello()
  {
   name=$1;
   echo "Hello , how are you $name";
 }

 hello "itin" ;

output is :

 Kaizen ~/so_test $ ./zhello.sh
  + ./zhello.sh                     --  script was run 
 ++ set -o functrace
 ++ hello itin                      -- function was invoked
 ++ name=itin                       -- variable assigned within the function hello 
 ++ echo 'Hello , how are you itin'
 Hello , how are you itin           -- printed the output from the function ...

I am a bit curious , is there something specific you looking for ?

share|improve this answer
    
I forgot to call it. Sorry, I'm new to the whole bash scripting thing. –  Brandon D. Jun 9 '13 at 16:56
    
@BrandonD , no problem .... all this helps learn !! –  kabirz.domain Jun 9 '13 at 17:01
add comment

The function hello() was not called at the end of script. User error.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.