Question

I know this question has kind-a started "religious" wars in past and there might not be one correct answer. But after working with ksh and csh for last 3-4 years and going through the pain of porting from one to another or applying a common piece of logic to multiple versions (read as legacy code), if I am writing a new script, I would go for ksh, but out of compulsion rather than choice. Is there a better option other than ksh/csh? Also something that is portable across Unixes (Solaris/HP/IBM/FreeBSD) and Linux (and if I am not asking too much or it if does make sense all Linux flavors)

Waiting for suggestions ...

Peace :) Devang Kamdar

Was it helpful?

Solution

I would suggest plain old sh, which is available everywhere.

Also, it is worth noting that portability involves not only shell but also other commands used in a script such as awk, grep, ps or echo.

OTHER TIPS

If you really want it to be portable (I don't know that any shell-script is maintainable), I would specify #!/bin/sh and test with dash and if possible other shells.

I would expect BASH to be the widest spread shell at the moment since it is the default for many Linux distributions (it can even run on Windows with cygwin, but that's probably true for the other shells, too). An alternative might be to not use the shell itself for scripting but one of the scriping languages out there like perl, python, ruby, ...

I usually use ksh. I find that it's a good compromise between features and portability. It's there (or a compatible version is available) on most Linux boxes and Solaris. It's a while since I used HP-UX (thankfully) but I'm pretty sure it was available there too.

If all the machines you need to support are modern, bash might be an option. Solaris 10 comes with a copy. It's the default on most Linux machines.

Your lowest common denominator is going to be Bourne (sh), so that's worth considering if portability is your main concern. It's missing some of the more friendly features of ksh and bash though.

It's still worth steering clear of csh/tcsh for scripting. Csh Programming Considered Harmful is an oldie but still largely relevant.

My answer would be perl.

Does everything 'sh' 'bash' etc can do in a nicer more elegant manner.

Also it is actually more portable. A given version perl is very consistant accross all platforms. There are no significant differences between the Linux, Solaris and AIX distributions whereas porting shell scripts between these platforms is a real pain.

And it works on all windows paltforms! Provided you avoid backticks and "system()" your script has a good chance of running.

Python! Check out iPython, which is an enhanced Python interpreter. Also: Python for Unix and Linux System Adminitration.

You can write great portable scripts, and it's fun.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top