Script conversion from SCO Open Server to Red HatEnterpriseneeded...

Bill Campbell bill at celestial.com
Wed Jun 7 09:36:44 PDT 2006


On Wed, Jun 07, 2006, Mike Schwartz (PC Support) wrote:
...
>     I appreciate all the good info.  Since filePro now has directory
>commands and so forth, I've been trying to do as much as possible within
>filePro, itself, so I've never learned the nuances of writing scripts that
>are portable between SCO Unix variants and Linux.
>
>     If anybody knows of a good reference that succinctly explains the
>differences, I would be interested in looking at it.  If not, are there any
>good references for making scripts as portable as possible between all of
>the Unix variants?

As a general rule, KISS is highly recommended.  Going from SCO's
/bin/sh scripts to other *nix shouldn't be much of a problem as
they're already close to the lowest common denominator.

I've found many more problems with scripts written by Linux bash
people who have little or no experience on other systems so make
use of things like fancy path expansions using ``{...}'' which
fail on pure /bin/sh implementations.  These are getting to be
less of a problem as more *nix systems use bash as their /bin/sh
(although this isn't something one would want to depend on).

It is always a good idea to use the approprriate ``spitshell'' in
the first line of the script ``#!/bin/sh'', ``#!/bin/ksh'', etc.
to insure that the system executes the shell you want it to or
throws an error if it isn't installed.

Debugging shell scripts can be a real bear since (a) the syntax
of the language doesn't encourage clean block structure, and (b)
many people who write the scripts have odd ideas of style.

One of the things I do when tackling these scripts is to add
commented curly braces to statements like ``if...fi'', and
``case...esac'' allowing me to use vi's ``%'' key to jump to
matching braces, and clean up the indentation using ``%>'' and
``^<'' to indent blocks of text to clean them up so they're
readable.

# I use double left braces here and in the ``fi'' to mark the
# entire ``if'' section.
if someexpression; then #{{
	# some code here
#}
else {
	# other code here
fi #}}

# in this case the left parens are used to match right parens in
# the case sections.
case "$something" in #{((
	something)	xxx ;;
	*)	yyy;;
esac #}

While this may appear a bit ugly, I find that allowing the editor
to easily detect block structure is invaluable (and I've never
had the patience to learn emacs :-).

I don't know of any prettyprinters for shell programs, but such
things probably exist, and that might be useful.  A google search
on ``prettyprint shell'' does return some references, at least
one to the dreaded emacs.

>     I have some customers who are locked into SCO Open Server for the
>foreseeable future because they have menu systems and other functions
>written in "C" and shell scripts, but they either do not have the source
>code for the "C" and/or it would be a horrendous job to re-write all the
>poorly documented shell scripts. It might be more expedient to attempt a
>rote translation of the commands in the shell scripts, rather than try to
>figure out the functionality of each one and rewrite each one from scratch. 

There are very few things in SCO shell scripts that will cause
compatibility problems.  The only one I can think of offhand is
the syntax of the ``echo'' command when one wants to leave the
cursor at the end of the line.

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``The end move in politics is always to pick up a gun.''
	-- Buckminster Fuller


More information about the Filepro-list mailing list