JP Vossen on 21 Apr 2010 12:33:08 -0700 |
> Date: Wed, 21 Apr 2010 12:46:12 -0400 > From: "K.S. Bhaskar" <ksbhaskar@gmail.com> [...] > # echo and options > ECHO=/bin/echo > ECHO_OPTIONS="" > #Linux honors escape sequence only when run with -e > if [ "Linux" = "`uname -s`" ] ; then ECHO_OPTIONS="-e" ; fi [...] Yes, giant PITA. echo is not POSIX...but printf [1] is... ### Bad, not portable, not POSIX: echo ... ### "Good," portable, POSIX: printf "%b\n" ... It's a little more typing than 'echo', but a lot less that the other portability solutions and so far has worked for me in practice. Caveat, I really don't run much on non-Linux anymore... I'll be interested to hear if that works as well as I think it does. <sidebar> I recommend you *not* develop on Linux if you need portable shell scripts. Linux & the GNU tools are *too* useful and friendly and helpful. Even if you know what you are doing, you'll still have issues. Find the oldest, crappiest system you need to run on, and develop (or at least alpha test) on that. Odds are that it'll be a lot easier to port forward to Linux than backwards from Linux to whatever. </sidebar> Later, JP _________________________ [1] printf refs: ## printf cheat sheet (tell me if you have a better one) http://www.opengroup.org/onlinepubs/009695399/functions/printf.html $ man 1 printf $ man 3 printf # maybe $ info coreutils 'printf invocation' | less $ help printf # bash [...] In addition to the standard format specifications described in printf(1) and printf(3), printf interprets: %b expand backslash escape sequences in the corresponding argument %q quote the argument in a way that can be reused as shell input ----------------------------|:::======|------------------------------- JP Vossen, CISSP |:::======| http://bashcookbook.com/ My Account, My Opinions |=========| http://www.jpsdomain.org/ ----------------------------|=========|------------------------------- "Microsoft Tax" = the additional hardware & yearly fees for the add-on software required to protect Windows from its own poorly designed and implemented self, while the overhead incidentally flattens Moore's Law. ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|