Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


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

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



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.




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org