[Discuss] Scripting languages (was Re: rsync v. cp in data migration)

Derek Martin invalid at pizzashack.org
Mon May 27 13:57:42 EDT 2013


On Mon, May 27, 2013 at 01:31:58PM -0400, Jerry Feldman wrote:
> Most Linux and Unix systems today do use the POSIX shell, but my
> training is when writing basic scripts, I do not rely on POSIX.

Right, and so is mine.  But gaf, you and I are old. =8^)  People who
are learning shell scripting now are learning how to write bash/POSIX
scripts, will all the new syntax included.  And there's some good
stuff in there, so it's valuable to learn.  But there are still
differences out there, such as the echo feature I mentioned.

Specifically, on SysV-derived systems, you need to specify the -e
option to echo for it to interpret escape sequences, whereas on
BSD-based systems, the -e option is not required for this, and if you
include it, it will output the string '-e'.  Dash behaves like the
latter, whereas bash behaves like the former.  This isn't the only
difference, but I don't write a lot of shell scripts these days, and
it's the only one I can remember off the top of my head.

If you want to use escape sequences portably in your echo commands,
then you end up having to write silly code like this:

    unset opte
    etest="$(echo -e "hello\n")"
    if ! echo $etest |grep -q 'e '; then opte='-e '; fi
    
    echo $opte "here's a line with a newline\n"
    
Note that you MUST NOT quote the $opte or else you will get a
leading space on BSD-alikes.

-- 
Derek D. Martin    http://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.



More information about the Discuss mailing list