We will be using both solaris and linux for quite a while (transition
takes a while). The shell scripts that we have (originally for solaris)
will not be portable due to differences in awk, sed and echo ( so far).
Also some scripts call java and perl. To solve this I was thinking of
creating a
setup.sh script ( to be sourced) where you do something like:
#!/bin/sh
OS_TYPE=`uname`
if [ "$OS_TYPE" = "Linux" ];then
ECHO=echo
AWK=/usr/bin/gawk
elif [ "$OS_TYPE" = "SunOS" ];then
ECHO=/usr/ucb/echo
AWK=/usr/bin/nawk
else
echo "Unknown os"
fi
Then in scripts I have to refer to $AWK or $ECHO when using the commands.
Is there a library that is not solaris or linux but cross plattform that
I can use for these commands? Any other hints on how to solve this?
cheers,
//mikael
Its worth looking into implementing some of the Solaris scripts using
the previous POSIX compliant versions of utilities (located in
/usr/xpg4/bin), as depending on what features you are using, you may
find some additional common ground whereby you can reduce the
dependency on the OS being used.
A common example of where I find this useful is with the support of
character classes (e.g. [[:digit:]] & \d, ...) & regexps within sed &
egrep which aren't supported in the standard Solaris versions.
I know this doesn't strictly answer your question, but it may assist in
finding a more "generic" solution.
Apologies if you are already aware of this.
Cheers,
Conor
How about:
[ -d /usr/xpg4/bin ] && PATH=/usr/xpg4/bin:$PATH
--
Chris F.A. Johnson | Author:
<http://cfaj.freeshell.org> | Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress
Reinventing the wheel, are we?
> Is there a library that is not solaris or linux but
> cross platform that I can use for these commands?
> Any other hints on how to solve this?
When talking about cross-platform ABIs, you will have to
be more specific than this for a good resource (which I
don't believe exists under this narrow categorization) -- but
that said, here are:
"scriptran"
http://soldc.sun.com/tools/linux/L3.html,$0,"Bourne shell script
analysis tool, to port Solaris .SH to Linux (SLPK): under Solaris;
within LXCP; specific to RedHat 5.2; AKA Solaris Transition Tool AKA
Pipeline Tool AKA SVMT"
The following software package has not been accessible for
at least a year now, but emailing the author and/or maintainer
is surely worth the time and effort, even if meant for AIX:
Document: "Port your Solaris application to Linux on POWER"
http://www-03.ibm.com/servers/enable/site/linux/landing/port_solaris.html?TACT=105AGX32&S_CMP=SOLLX&ca=dos-migratelx,$0,"Solaris
=> Linux migration"
Discussing Solaris _binaries_, but worth looking at:
"shanalyze"
http://h21007.www2.hp.com/dspp/tech/tech_TechSoftwareDetailPage_IDX/1,1703,6731,00.html;http://h21007.www2.hp.com/dspp/files/unprotected/slpk/slpkpresentation.pdf,,"Solaris
=> Linux migration tools (LXCP): within Solaris-Linux Porting Kit
(SLPK)",<rapid.m...@hp.com,slpk.s...@hp.com>
As far as documents which specifically mention porting issues,
here is another listing, which I presume may well end up having
more "real world" value to you than the above resources.
Document: "The Solaris Migration Cookbook: Solaris-Linux Compatibility
Tools.postscript" in the LXCP/scriptran distribution
and ...
D,"comp.unix.shell - how to write portable shell
scripts?",2005-06-29,http://groups-beta.google.com/group/comp.unix.shell/browse_frm/thread/72466c66cff65f32/66d06d746e6c5ad7?q=group:comp.unix.shell+insubject:portable&rnum=1&hl=en#66d06d746e6c5ad7,$0,".TXT"
D,"22. Writing Portable Bourne
Shell",,http://sources.redhat.com/autobook/autobook/autobook_208.html#SEC208,$0,"website"
D,"On the Development of a Shell Scripting Style and
Standard",,http://www.hdgonline.net/metadot/index.pl?id=2762&isa=Category&op=show_printer_friendly,$0,"","David
W. Myers" <dwm...@mindspring.com>
D,"Migrating from the System V Shell to the POSIX
Shell",1997-1999,http://www.unix.org/whitepapers/shdiffs.html,$0,"webpage","The
Open Group"
D,"POSIX.2 and Shell
Links",,http://www.in-ulm.de/~mascheck/various/shell-links/,$0,"webpage","Sven
Mascheck <masc...@in-ulm.de>
D,"The Traditional Bourne Shell
Family,2005-06-18,http://www.in-ulm.de/~mascheck/bourne/,$0,"webpage","Sven
Mascheck <masc...@in-ulm.de>
D,"Autoconf -- Creating Automatic Configuration Scripts: chapter 10 --
Portable Shell
Programming",2003-11-05,http://www.gnu.org/software/autoconf/manual/autoconf.pdf,$0,"from
autoconf documentation","David MacKenzie", "Ben Elliston", "Akim
Demaille"
^? D,"22. Writing Portable Bourne
Shell",,http://sources.redhat.com/autobook/autobook/autobook_208.html#SEC208,$0,"chapter
22 of 'Gnu Autoconf, automake, and libtool'",Gary V. Vaughan; Ben
Elliston; Tom Tromey; Ian Lance Taylor
D,"Filesystem Hierarchy
Standard",2.3,http://www.pathname.com/fhs/,$0,"webpage","Rusty
Russell", "Daniel Quinlan"
D,"The Open Group: The Single UNIX
Specification",3,http://www.unix.org/version3/online.html,$0,"website"
^ "The Open Group Base Specifications, Issue 6, IEEE Std 1003.1, 2003
Edition". The IEEE and The Open Group.
<URL:http://www.opengroup.org/onlinepubs/007904975/>.
^ D,"The Open Group: Base Specifications: Shell &
Utilities",6,http://www.opengroup.org/onlinepubs/009695399/utilities/contents.html,$0,"website"
^ D,"sh - shell, the standard command language
interpreter",,http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html,$0,"webpage"
D,"UNIX Portability
Notes",,http://cr.yp.to/docs/unixport.html,$0,"webpage","Daniel J.
Bernstein"
D,"Migrating from the System V Shell to the POSIX
Shell",,http://www.unix.org/whitepapers/shdiffs.html,$0,"webpage",
D,"What to watch out for when writing portable shell
scripts",2004-03-04,http://programming.newsforge.com/article.pl?sid=04/03/01/1554205&mode=nested;http://programming.newsforge.com/programming/04/03/01/1554205.shtml;http://programming.newsforge.com/print.pl?sid=04/03/01/1554205,$0,"website","Peter
Seebach" <se...@plethora.net>
http://code.dogmap.org/
D,"DEVELOPING PORTABLE
SOFTWARE",,http://www.cs.wvu.edu/~jdm/research/portability/tutorial/,$0,"tutorial"
D,"On the Development of a Shell Scripting Style and
Standard",2004-02-21,http://home.comcast.net/~dwm042/Standards.htm,$0,"webpage","David
W. Myers" <dwm...@mindspring.com,dwm...@comcast.net>
D,"Achieving Unix / Windows Portability Using Intersection: The Typhoon
Approach",,http://www.raycosoft.com/rayco/support/SANS_2001_files/frame.htm;www.sans.org/SANS2001/techcon.htm,$0,"website:
NCA","Dr. Richard Anderson"
This is a reasonably comprehensive listing of shell resources
and information on this matter.
=Brian
What I usually do is:
#! /bin/sh -
# start a POSIX shell on Solaris where /bin/sh is Bourne:
false ^ true &&
[ -x /usr/xpg4/bin/sh ] &&
exec /usr/xpg4/bin/sh - "$0" ${1+"$@"}
PATH=$(command -p getconf PATH; :)${PATH+:}$PATH
export PATH
"; :" is to work around a bug in most kshs (including Solaris
/usr/xpg4/bin/sh).
And I don't use "echo", I use "printf", as recommended by POSIX.
--
Stéphane
I usually do
#!/bin/sh
PATH="/usr/xpg4/bin:/bin:/usr/bin:/usr/sbin:/sbin"
export PATH
and use plain
awk ...
sed ...
and rather than echo use
printf "%s\n" "text"
--
Michael Tosch @ hp : com
we at S7 [s7solutions.com] specialize in cross-platform porting &
migration and in fact we have a tool called "Linux-it" which analyses
the unix code and converts the code to suit linux. Infact it even does
a one round of analysis to inform how suitable is the source code for
porting. If you are interested please do get in touch with us.
Best Regards
Manju
*** CUSTOMER comes FIRST, come what may ********
Manjunath M
S7 Software Solutions Pvt. Ltd.
#83 Railway Parallel Road, Kumara Park West
Bangalore - 560020, India
Telephone: +91-80-51526777
Fax: +91-80-2334135
2936 173rd CT NE
Redmond, WA 98052, USA
Telephone: (425) 867 1457
Fax: (425) 883 2597
Toll Free: 1-888-224-6174
Yahoo messenger ID: s7softwaresolutions
MSN messenger ID: manj...@hotmail.com
Skype ID: s7softwaresolutions
"Redefining cross-platform porting & migration"
************************************************