Operating System - HP-UX
1833588 Members
4161 Online
110061 Solutions
New Discussion

Where to find one Shell Script Programming Editor

 
SOLVED
Go to solution
albert_hua
Frequent Advisor

Where to find one Shell Script Programming 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. (三人行必有我师也)
15 REPLIES 15
Peter Kloetgen
Esteemed Contributor

Re: Where to find one Shell Script Programming Editor

Hi Albert,

do you know the command:

set -o xtrace (to turn on debugging mode)
set +o xtrace (to turn off debugging mode)

put the first command line as first line into your script, the second one as last line. You will get an output which shows you how the shell interprets a command line before executing it and after that the normal output of command lines.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Steve Steel
Honored Contributor

Re: Where to find one Shell Script Programming Editor

Hi

That is good advice

man sh-posix and go to the bottom of page-13

there you will find

| set [{-|+}abCefhkmnopstuvx] [{-|+}o option]... [{-|+}A
name] [arg]...


There are lots of interesting things there


FYI

1)Easy way toprint man page

man $*|lp -dprinter -on -otl66 -ol70

2)see
http://www.introcomp.co.uk/unixadmin.html

Lots of example scripts


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
albert_hua
Frequent Advisor

Re: Where to find one Shell Script Programming Editor

Thanks a lot for your advice.
But can I execute the shell program step by step or set some break points so that I can check the output interactively.

Al.
When going with others together, I can always find my adviser among them. (三人行必有我师也)
Peter Kloetgen
Esteemed Contributor

Re: Where to find one Shell Script Programming Editor

Hi Albert,

there is the possibility to let your script stop for a desired time period, use the command:

sleep time_in_seconds

to get the desired output, for example the value of a variable, you have to use the command:

echo $variable

which you can put into your script. To find logical errors, you can use the command:

if test $var -ne desired_value
then
exit 1
fi

With exit you can set a return code for your script. The values can be 0-255.

To check the return code of a command, do the following:

command_to_be_run
echo $?

this will give you the return code of the last command.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
V. V. Ravi Kumar_1
Respected Contributor

Re: Where to find one Shell Script Programming Editor

hi,

in the code at appropriate points put
echo "press any key to continue"
read char

so that unless u press any key it won't proceed
regds
ravi
Never Say No
albert_hua
Frequent Advisor

Re: Where to find one Shell Script Programming Editor

Yes, these advises are exactly smart skills but I still do not believe that there is no product to help programmers to write shell scripts conveniently. After all, there are still many people who need to write shell scripts.

Al.
When going with others together, I can always find my adviser among them. (三人行必有我师也)
Peter Kloetgen
Esteemed Contributor

Re: Where to find one Shell Script Programming Editor

Hi Albert,

i am working as trainer for Hewlett Packard in Germany, and i do courses in shell programming. Sorry for the bad news, but i don't know a tool for debugging shell scripts in HP-UX or any other UNIX/Linux.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Tom Geudens
Honored Contributor

Re: Where to find one Shell Script Programming Editor

Hi,
I'm attending an HP course right at this moment (writing this during a break :-) and the only thing the teacher can come up with (and which I already knew) is executing the script with "sh -x" in front of it.

When making large scripts, consider the use of functions. Makes it a lot easier ...

Regards,
Tom
A life ? Cool ! Where can I download one of those from ?
albert_hua
Frequent Advisor

Re: Where to find one Shell Script Programming Editor

Hi, everyone:
So what I can do when I want to debug one shell program is to use 'set -o trace' or 'sh -x' and then add some self-designed 'echo' or other commands to trace the error at last?
I think perhaps you are right. Maybe people do not use shell script to develop large projects so that people think these small tools are enough to produce good programs.
Thanks everyone who remark.

AL.
When going with others together, I can always find my adviser among them. (三人行必有我师也)
Daimian Woznick
Trusted Contributor

Re: Where to find one Shell Script Programming Editor

I have written some fairly large shell scripts and sorry, I don't know of any debug tools that you can purchase. However, the following links provide some tutorials on shell programming:

http://www.injunea.demon.co.uk/pages/page201.htm

http://steve-parker.org/sh/sh.shtml

http://www.cbi.cnptia.embrapa.br/manual/unix/unix_intro/Shell.html

The following link provides information on debugging that you may find of use:

http://www.injunea.demon.co.uk/pages/page213.htm


I have always found it easier when coding a large project to always split from the main program and call subroutines. Another coding hint would be to take a chunk at a time in a smaller script and when the code is correct, incorporate it into the larger script. This will prevent debugging the larger code all the time.

Hope this helps.
Bill Hassell
Honored Contributor

Re: Where to find one Shell Script Programming Editor

Actually, you can have your shell script run page by page:

sh -x shellscript 2>&1 | more

The output of the tracing goes to stderr so it must be redirected to stdout and then piped to more. That way, you can run down the list until a problem occurs, then use CTRL-C to abort and you'll have the trace to that point. Note that functions called in the script will not inherit the -x (or set -x) option, so one technique is to export a TRACEON variable at the beginning of the script:

export TRACEON=/sbin/true

then in all the functions (and main too):

if $TRACEON || set -x

Another hint: always use set -u (you'll avoid big oops prob lems due to misspelled variables).

Another place to post your question is in Usenet: comp.unix.shell

And a great location for shell scripting techniques: www.shelldorado.com


Bill Hassell, sysadmin
Gregory Fruth
Esteemed Contributor

Re: Where to find one Shell Script Programming Editor

Presumably you're talking about the POSIX shell
or the (shudder) Bourne shell. These are largely
compatible with the Korn shell, for which there is
a rudimentary but freely available debugger called
kshdb. Perhaps you can use kshdb to debug your
script.

I have not use kshdb in quite some time (for longer
scripting tasks I find Perl to be better suited) but
as I recall kshdb supports breakpoints and stepping.
You can also execute arbitrary shell commands
at the debugger prompt.

You can find more info on kshdb in the O'Reilly book
"Learning the Korn Shell"
(http://www.oreilly.com/catalog/korn2/).
In the past kshdb was available at ftp.uu.net. Perhaps
a web search will turn up its current location.

HTH



Anonymous
Not applicable

Re: Where to find one Shell Script Programming Editor

Does this make you a happy camper?
HTH, Tom.
---
http://www.nedit.org : free software (GPL).

http://www.nedit.org/about/features.shtml
NEdit is a standard GUI (Graphical User Interface) style text editor for programs and plain-text files. Users of Macintosh and MS Windows based text editors should find NEdit a familiar and comfortable environment. NEdit provides all of the standard menu, dialog, editing, and mouse support, as well as all of the standard shortcuts to which the users of modern GUI based environments are accustomed. For users of older style Unix editors, welcome to the world of mouse-based editing!
...
Features for programmers
State of the art syntax highlighting with built-in patterns for C, C++, Java, Ada, FORTRAN, Pascal, Yacc, Perl, Python, Tcl, Csh, Awk, HTML, LaTeX, VHDL, Verilog, and more.
Auto-indent, programmable language-sensitive smart-indent.
Block indentation adjustment
Parenthesis flashing and matching
Find lines directly from compiler error output
Tab emulation
Unix ctags support
Client/Server mode for integration with software development tools.

albert_hua
Frequent Advisor

Re: Where to find one Shell Script Programming Editor

Thomas:
Thanks for your sincere help.
I have downloaded this software.
It seems terrific.
I think I will try to use it and recommend it to others.

Al.
When going with others together, I can always find my adviser among them. (三人行必有我师也)
Anonymous
Not applicable
Solution

Re: Where to find one Shell Script Programming Editor