On Sun, Jan 07, 2001 at 05:12:06PM -0800, Brad Doster <[EMAIL PROTECTED]> wrote:
| zap_word() {
|         # Arguments:    "word to delete" "word list to delete from"
|         echo $2 | sed "s/^/ / ; s/$/ / ; s/ $1 / / ; s/^ // ; s/ $//"
| }
| 
| In this case, double quotes are needed because of the $1 usage.  I was
| delighted when Matthew suggested the double quotes, as that got it working
| for me.  Even better though, is now I understand *why*. :)

Just for the good habit, recode that as:

zap_word() {
        # Arguments:    "word to delete" "word list to delete from"
        echo "$2" | sed "s/^/ / ; s/\$/ / ; s/ $1 / / ; s/^ // ; s/ \$//"
}

That is, make sure $2 is properly quoted. It'll work fine as is until
the day you say:

        zap_word "foo  bar"     # nb: there's 8 chars in that string

Also backslash the $s in your sed which _aren't_ parameter subs.

By adopting these habits you make you code more robust against the
unanticipated needs of the future.

Cheers,
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

There are old climbers, and there are bold climbers; but there are no old
bold climbers.



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to