bash - Best/conventional method of dealing with PATH on multiple UNIX environments -
the main question here is: there standard method of writing unix shell scripts run on multiple unix platforms.
for example, have many hosts running different flavours of unix (solaris, linux) , @ different versions different file system layouts. hosts have whoami in /usr/local/gnu/bin/, , in /usr/bin/.
all of our scripts seem deal in different way. have case statements on architecture:
case "`/script/that/determines/arch`" in sunos-*) whoami=`/usr/local/gnu/bin/whoami` ;; *) whoami=`/usr/bin/whoami` ;; esac
with approach know binary being executed, it's pretty cumbersome if there lots of commands being executed.
some set path
(based on arch script above) , call commands name. convenient, lose control on command run, e.g. if have:
/bin/foo /bin/bar /other/bin/foo /other/bin/bar
you wouldn't able use both /bin/foo
, /other/bin/bar
.
another approach think of have local directory on each host symlinks each binary needed on each host. e.g.:
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 people use? please don't write script in python... there tasks bash succinct , practical means of getting simple task accomplished.
i delegate .profile, has elaborate series of internal functions try directories add path. except on osx, believe impossible because darwin/fink/ports each wants control path, approach works enough.
if cared ambiguity (multiple instances of foo
in different directories on path), modify functions identify ambiguous commands , require manual resolution. environment, has never been issue. main concern has been have single .profile runs on debian, red hat, solaris, bsd, , on. 'try every directory possibly work' approach works enough.
Comments
Post a Comment