LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do you debug a bash script (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-you-debug-a-bash-script-293906/)

meadensi 02-23-2005 11:28 AM

How do you debug a bash script
 
Hello,

Ok I've been typing in a bash script from a book and I successfully found some typos and got rid of them. Also, I got help earlier from here about for loops. So I've made progress but I'm stuck again.

I suppose my question is how do you debug a bash script. I have Fedora Core 3 running on a legacy machine, so no GUI just command line only. At the moment all I know is how to use VI. What other tools are good? For example, is there a tool that I can use to print out lines 53-56 from a script.
I remember tail from a course but that only did the lines at the end of a script.

I have checked the listing against the book and I'm getting
Code:

:command not found
:command not found
:command not found
:command not found
:command not found
:command not found
:command not found
:command not found
-bash: chok3: line 380: syntax error: unexpected end of file

It seems to be something to do with variable declarations having a comment # at the end.

How can I make these go away?

More importantly the later lines that instruct iptables are not being executed because iptables -L gives the default.

I think that I have a problem similar to a missing close quote but I can see none.

Do any of this make sense to you guys?

Regards,
Meadensi

Blinker_Fluid 02-23-2005 11:35 AM

With vi you can type: 53G to go to line 53

Brain Drop 02-23-2005 11:44 AM

If you either:
Code:

set -x
or
Code:

bash -x scriptname
bash will echo each command in the script before execution, either globally, or for a certain process.

meadensi 02-23-2005 11:54 AM

Thanks,

Code:

bash -x scriptname
This give loads of info and now I am making progress again.

Cheers,
Meadensi

meadensi 02-23-2005 01:47 PM

Ok, so new problem
 
People,

Ok so now I have a new problem. When I run the code (using the bash -x option ) ...
Code:

# Enable broadcast echo Protection
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

I get the response
Code:

+echo 1
:No such file or directoryet/ipv4/icmp_echo_ignore_broadcasts

Now we can see that the error message "No such file or directory" is being merged with the pathname "/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts". I highlighted them in color.

The pathname is definitely valid. I do not know why this is happening? This is my first script, albeit out of a book so some configurations options may yet need changing.

Any ideas?
Meadensi


All times are GMT -5. The time now is 02:30 PM.