JP Vossen on 21 Apr 2010 12:33:08 -0700

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] portable echo (was: Re: Shell scripting?)

> Date: Wed, 21 Apr 2010 12:46:12 -0400
> From: "K.S. Bhaskar" <>

> # echo and options
> ECHO=/bin/echo
> #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.

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.

[1] printf refs:

## printf cheat sheet (tell me if you have a better one)

$ 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            |:::======|
My Account, My Opinions     |=========|
"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         --
Announcements -
General Discussion  --