bug-gnu-utils
[Top][All Lists]
Advanced

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

A bug in Bourne - horrors!!


From: Jim Easton
Subject: A bug in Bourne - horrors!!
Date: Sat, 7 May 2005 01:36:14 -0600 (MDT)

Dear People,

I have no good idea of who to send this to - I picked you - sorry.

I've been writing Bourne shell scripts for over 20 years and
although I've been aware of the herein discribed behaviour I
have only recently come to view it as a bug.

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.

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.

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.


#!/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

echo "$LIST"




reply via email to

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