Debugging functions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Debugging functions
# 1  
Old 06-09-2013
Debugging functions

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?

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?

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

output:

Code:
user@mac11:53:29~/desktop bash -x debug.sh 
+ echo 'Hello World'
Hello World
user@mac11:54:55~/desktop

# 2  
Old 06-09-2013
Your function would be debugged - if you ever called it.
Code:
$ cat myScript
set -x
echo "Hello World"
hello() {
    echo "Hello world"
}

hello


$ ./myScript
+ echo 'Hello World'
Hello World
+ hello
+ echo 'Hello world'
Hello world

This User Gave Thanks to Scott For This Post:
# 3  
Old 06-09-2013
Is debug.sh a built in function?
If yes, how to use it?
# 4  
Old 06-10-2013
Quote:
Originally Posted by juzz4fun
Is debug.sh a built in function?
If yes, how to use it?
No, debug.sh is the name of BrandonD's shell script. The contents of debug.sh is shown in the 1st CODE tagged section of the 1st message in this thread. Smilie
# 5  
Old 06-10-2013
I suppose it would be wise to call it, but in some scripts that I've seen do call the function. That's probably where I picked up that practice from. Is there any behavioral difference if a function is called or not?
# 6  
Old 06-11-2013
If a function is never called, then it should be deleted, since it just fills up the space Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

2. Programming

c++ debugging

hey i have a problem with a switch case in program and the debugger is messy has hell ( we use normal VI and gdb in our schoool to make it more diffiacult) any way i have a problom where for some unknown reason the debugger just skips a switch statment as if it wasent even there the rest... (2 Replies)
Discussion started by: gotenxds
2 Replies

3. UNIX for Dummies Questions & Answers

blcr debugging

hey, can any one please tell me how can i debug blcr?? actually i have checkpointd a client using blcr and i want to check out what actually happens when we checkpoint any program. so i want to see what happen when we type $cr_checkpoint pid i mean i want to debug when i enter this... (0 Replies)
Discussion started by: pratibha
0 Replies

4. Homework & Coursework Questions

Fixer Debugging

School:Syrian Virtual University - Bachelor in Information Technology - Tutor: A.Issa - course: S10-iti320 hi all, would you please help me correcting and debugging this script: fx-permiss.sh which accepts a list of users as argument resiting those files permissions: say our directory... (0 Replies)
Discussion started by: erzal
0 Replies

5. Shell Programming and Scripting

Fixer Debugging

hi all, would you please help me correcting and debugging this script: fx-permiss.sh which accepts a list of users as argument resiting those files permissions: say our directory structure: /home/erzal/file /home/erzal/dire /home/erzal/share /home/erzal/share/file /home/erzal/share/dire 1-... (1 Reply)
Discussion started by: erzal
1 Replies

6. Shell Programming and Scripting

script debugging

is there any way you can add a breakpoint in a script so you can stop on it? i have used -xv in my shebang but the script just runs and i want it to stop at a specific point in the script. appreciate any help. (1 Reply)
Discussion started by: npatwardhan
1 Replies

7. Solaris

debugging

when I tried to debug my application i got the following. gdb -v GNU gdb 6.6 file is in C and Xmotiff Languages (gdb) attach 25499 Attaching to process 25499 Retry #1: Retry #2: Retry #3: Retry #4: 0xfea40b68 in ?? () (gdb) where #0 0xfea40b68 in ?? () (0 Replies)
Discussion started by: satish@123
0 Replies

8. Shell Programming and Scripting

debugging a script??

Hi all, Am working on a script to understand the flow control of it.. Since i am from a C background i looking out for an easy way to analyze the script as it runs .. In C/C++ we have F7 that starts execution from main() and proceeds accordingly.. I was wondering if there is a same approach... (2 Replies)
Discussion started by: wrapster
2 Replies

9. Programming

Semaphore debugging

I'm running one multithreaded application, in that one of my thread is waiting infinitely in a semphore. Is there a way to determine, in which semaphore the particular thread is waiting and which thread(s) is holding the semaphore. (5 Replies)
Discussion started by: ptprabu
5 Replies

10. Shell Programming and Scripting

Regarding Debugging

Hi, If we want to debug a shell script, then set -vx has to be included in the begining of the script. Just i want to know what purpose -vx is used. Thanks in advace Sarwan (2 Replies)
Discussion started by: sarwan
2 Replies
Login or Register to Ask a Question