Devang Kamdar
Devang Kamdar

Reputation: 5927

What is the best (portable and maintanable) Shell Scripting language today?

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

Upvotes: 6

Views: 3219

Answers (6)

ShawnMilo
ShawnMilo

Reputation: 6205

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.

Upvotes: 0

James Anderson
James Anderson

Reputation: 27478

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.

Upvotes: 0

Stephen Darlington
Stephen Darlington

Reputation: 52565

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.

Upvotes: 2

TheMarko
TheMarko

Reputation: 8654

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, ...

Upvotes: 2

mouviciel
mouviciel

Reputation: 67859

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.

Upvotes: 9

Matthew Flaschen
Matthew Flaschen

Reputation: 284927

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.

Upvotes: 4

Related Questions