The main question here is: is there a standard method for writing UNIX shell scripts that will run on multiple UNIX platforms.
For example, we have many hosts that work with different versions of UNIX (Solaris, Linux) and in different versions with slightly different file system layouts. Some hosts have whoami in / usr / local / gnu / bin /, and some in / usr / bin /.
All of our scripts seem to deal with this a bit differently. Some of them have arguments regarding architecture:
case "`/script/that/determines/arch`" in
sunos-*) WHOAMI=`/usr/local/gnu/bin/whoami` ;;
*) WHOAMI=`/usr/bin/whoami` ;;
esac
With this approach, you know exactly which binary is executing, but it is rather cumbersome if you are executing many commands.
Some simply install PATH(based on the arch script above) and invoke commands only by name. This is convenient, but you lose control over which command you execute, for example. if you have:
/bin/foo
/bin/bar
/other/bin/foo
/other/bin/bar
You can not use both /bin/fooand /other/bin/bar.
Another approach that I could think of is to have a local directory on each host with symbolic links to each binary file that is required on each host. For instance:.
Solaris host:
/local-bin/whoami -> /usr/local/gnu/bin/whoami
/local-bin/ps -> /usr/ucb/ps
Linux host:
/local-bin/whoami -> /usr/bin/whoami
/local-bin/ps -> /usr/ps
What other approaches do people use? Please don't just say, write a script in Python ... there are some tasks where bash is the most concise and practical way to achieve a simple task.