Discussion Locked

Shell Script NOT READILY portable ?

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm new to UNIX and am presently learning scripting...From what I read so far about this platform: diff flavors, diff shells, diff util/program versions...
It seems scripts are not readily portable,...to another machine,..another flavor of UNIX. There's a chance the same script won't run correctly w/o tweaking, right ?
Thx

7 replies

by ken.cunningham

Hi,

I've worked with quite a few flavours of unix and I have to say that I've found most of the scripting I've done can be ported around without any problem. That's not to say that everything works first time every time, but the problem is usually fairly easy to find.

As far as operational differences between flavours are concerned, you might find:

http://home.earthlink.net/~bhami/rosetta.html

useful as a comparison of commands between flavours. I wonder whether anyone knows of something similar for the more commonly used shell scripting commands.

Enjoy yourself.

by cavedweller

There are a couple of problems you might run into.

The first is that your default shell may be different on different machines or you may be using an obscure shell which isn't available everywhere. Your best bet is to stick to sh or csh. Be sure to start your scripts "#!/bin/sh" or "#!/bin/csh" to alert the OS to which shell you meant to run in.

The second problem is when you use vendor-specific command extensions or variations. For instance, SCO uses "tape status" where Sun uses "mt-f /dev/rmt/0 status" to check your tape drive.

Most commands are the same, however, and the basic shell syntax is too. If you need to write scripts which run on multiple platforms you might occasionally need to branch based on the results of "uname -r" (os name and version) when you use an implementation-specific command.

by jay allen

I second cavedweller answer, ALWAYS begin your scripts with #!/bin/ksh or something similiar depending on where the shell is located and TEST your scripts. Remember shell commands are portable but external commands can be trickier based on the OS. Ihave little to tweak my scripts but it happens. Good Luck!

This discussion is closed to new replies.