LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-23-2005, 11:28 AM   #1
meadensi
LQ Newbie
 
Registered: Feb 2005
Posts: 18

Rep: Reputation: 0
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
 
Old 02-23-2005, 11:35 AM   #2
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
With vi you can type: 53G to go to line 53
 
Old 02-23-2005, 11:44 AM   #3
Brain Drop
Member
 
Registered: Feb 2003
Location: just outside reality
Distribution: balanced
Posts: 752

Rep: Reputation: 35
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.
 
Old 02-23-2005, 11:54 AM   #4
meadensi
LQ Newbie
 
Registered: Feb 2005
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks,

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

Cheers,
Meadensi
 
Old 02-23-2005, 01:47 PM   #5
meadensi
LQ Newbie
 
Registered: Feb 2005
Posts: 18

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[debug]what does the following debug information mean icoming Programming 21 06-08-2004 02:13 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
Bad Argument '53' IPtables doesn't run and has no bash debug lines? piratebiter Linux - Security 3 09-02-2003 10:18 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM


All times are GMT -5. The time now is 08:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration