Chris Benson wrote: > If you do want ammo, my war-story is: I'm doing some Perl courses at IBM > in the UK, Perl is *the* scripting language used for writing tests and > product builds for MQ, the SSA disk group ... and the Java development > group. Their main requirements are a common language across all > platforms: none of this :- > case `echo "X\c"` in > X?c) ECHON=-n ;; > *) ECHOC='\c' ;; > esac > echo $ECHON "Some prompt: $ECHOC" > or > case `uname -o` in > Solaris) # ... > ;; > AIX) # ... > ;; > HPUX) # ... > ;; > esac > which doesn't work on OS/400, OS/2 and Win32 'cause there's no shell ...
Here's another war story. You want to find the home directory and shell of user $myuname. $HOME and $SHELL environment variables are unreliable (especially if running via "su"). The best I could come up with is: myhome=`csh -fc "echo ~$myuname"` myshell=`egrep "^$myuname:" /etc/passwd | sed -e 's/^..*:\(..*\) *\$/\1/'` But some Linux systems don't have csh. And using /etc/passwd is unsound -- what if they are using NIS+, say? True, I'm not up-to-date with the latest Korn shell (it may have a way to solve this); I tend to use /bin/sh if I need high portability (i.e. Korn shell and/or Perl may not be installed) and Perl for everything else. In Perl, this problem is easily and soundly solved by calling the getpwnam() function. Larry summarizes it with: "It is easier to port a shell than a shell script" I have written many cross-platform shell scripts, but it is much easier to do in Perl. Joseph N Hall sums it up in "Effective Perl Programming", Introduction: "Can you write cross-platform shell scripts? Yes, but with extreme difficulty. Most mere mortals should not attempt such things. Can you write cross-platform Perl scripts? Yes, easily." Another point not mentioned yet is that Perl is far superior to shell for writing secure scripts: it relies much less on forking external commands and has a unique "taint mode" feature. Just curious: why do they prefer Korn shell over bash, say? /-\ http://personals.yahoo.com.au - Yahoo! Personals New people, new possibilities. FREE for a limited time.