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

Re: ascii characters in echo statements




charles@lunarmedia.net said:
> I am trying to write a shell script that uses:
> 
> echo "set w4day='ls *.4 | cut -d . -f 1-5'" > bk_$domain.sh

That should work.

> So, when I put it into my shell script, I have to translate some
> characters as so:
> 
> echo "set w4day=\140ls \052.4 | cut -d . -f 1-5\140"

I'm not sure I understand why you'd want to escape those characters,
but because the behavior of echo varies so widely, I usually use
printf(1) for stuff like that.

    osiris:~$ printf 'set w4day=\0140ls \052.4 | cut -d . -f 1-5\0140\n'
    set w4day=`ls *.4 | cut -d . -f 1-5`

Ah, now that I tried it, I see what you are doing.  If you use ''
around that string, you can safely put `` inside it.  So

    echo 'set w4day=`ls *.4 | cut -d . -f 1-5`'

will work fine.

Steve
-- 
steve@silug.org           | Linux Users of Central Illinois
(217)698-1694             | Meetings the 4th Tuesday of every month
Steven Pritchard          | http://www.luci.org/ for more info

--
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.