General
cancel
Showing results for 
Search instead for 
Did you mean: 

Where to find one shell script editor

albert_hua
Frequent Advisor

Where to find one shell script editor

Hi, everyone:
I am a freshman towards shell script programming. Recently I have written a shell script which is about 300 sentences long. I just know to write a file with shell commands and then execute it directly under the current shell. Then some grammar errors occur. Grammar errors are relatively easy to position and correct but unfortunately there is some logical erros which are not easy to find without some tool aid. When I write C, I can find those logical errors easily with breakpoint or single step, etc. So I wonder whether there is some tools for shell programming providing the similar functions just as Turbo C. How and where can I get it? Thanks a lot!

Al.
When going with others together, I can always find my adviser among them. (三人行必有我师也)
4 REPLIES
Stefan Farrelly
Honored Contributor

Re: Where to find one shell script editor


When you run your script use the -x option and it will echo you every single line as it executes it so you can spot errors immediately.

eg.

sh -x ./<script> | more
Im from Palmerston North, New Zealand, but somehow ended up in London...
Reinhard Burger
Frequent Advisor

Re: Where to find one shell script editor

Hi Al
Just a small extension to the answer of Stefan.

if you use a tee in the pipe this will alow you to create a logfile. So you are able to read easily each script line and it's corresponding output.
In addition you can use the produced file for documentation ( if needed)

command will be then :

sh -x ./<script> | tee script.log | more
keep it simple
V. V. Ravi Kumar_1
Respected Contributor

Re: Where to find one shell script editor

hi,

thereis nothing better than vi. but as already replied

sh -x <script> 2>&1 will give some info

insert some sleep or accepting input statements so that u can track.

regds
Never Say No
Steve Post
Trusted Contributor

Re: Where to find one shell script editor

Sometimes I.....

Copy the busted piece of code to new, just to make sure it works the way I expect. Divide and conquer. When it works I copy it back into the program.

Add lines like this to the code....
#-----debugging-----------
echo "VAR should be skippy"
echo "VAR is $VAR"
echo "hit return to continue......"
read bogus_var
#-----debugging-----------
I get rid of the lines when it works right.

When I run the code I....
sh -xv myprog.sh 2>myprog.debug
Then vi file myprog.debug