[Top][All Lists]

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

Re: A bug in Bourne - horrors!!

From: Bob Proulx
Subject: Re: A bug in Bourne - horrors!!
Date: Sat, 7 May 2005 12:08:40 -0600
User-agent: Mutt/1.5.9i

Jim Easton wrote:
> I have no good idea of who to send this to - I picked you - sorry.

Well, if you are really talking about the classic Bourne shell then
probably not much can be done to help you.  That shell is purely
legacy today.  But if you are talking bash then I would suggest the
bug-bash mailing list.

> The problem is: Lines appear to be scanned even when they are
> enclosed in single quotes. If I may quote from the bash man page,
> (Red Hat Linux release 9) this seems wrong:
>   Enclosing  characters  in  single quotes preserves the literal value of
>   each character within the quotes.  A single quote may not occur between
>   single quotes, even when preceded by a backslash.

You seem to be confusing forward single quotes with backward single
quotes.  Commonly called single quotes and back ticks.  They are

> One writes some code (sed for example) that needs to escape some
> characters with a backslash and one runs it in plain sequence to
> debug it.  Then when one is satisfied that it is working one puts
> back-quotes on it and assigns it to a variable.  Trouble is it no
> longer works because the shell has done an additional scan of the
> code dispite the fact that the relevant code is enclosed in single
> quotes.

That problem was fixed in the POSIX shell by using $(...) instead of
using `...`.  Unless you truly need Bourne shell compatibility I
suggest that you use $(...) instead.

> Even if you agree it's a bug bearing in mind how many scripts must
> depend on it I don't imagine you can do much about it.  There are
> already upteen zillion options - what's one more??  :-)
> Following is a simple example.

Thank you for providing a very nice example.

> #!/bin/sh
> # Bourne shell has a bug?  (rescanning /\\$/ and \n)
> # Can be avoided by putting the procedure in a function or
> # can also be avoided by putting \\ in front of \\$ and \n ie. \\\\$ \\\n
> DATA='test line one\\
>       a continuation line'
> echo "$DATA"          # the variable DATA has only one "\" in it.
> echo %%%%%%%
> echo "$DATA" | sed '/\\$/s/^/AA/'     # the substitution occurs.
> echo -------------
> LIST=`echo "$DATA" | sed '/\\$/s/^/AA/'               # No substitution

You missed the closing backtick there.

> echo "$LIST"

Try this:

  LIST=$(echo "$DATA" | sed '/\\$/s/^/AA/')

  echo "$LIST"


reply via email to

[Prev in Thread] Current Thread [Next in Thread]