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

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

Re: GNU sed Bug (Single Quotes in Comments Cause Errors)


From: Jonathan Levi MD
Subject: Re: GNU sed Bug (Single Quotes in Comments Cause Errors)
Date: Mon, 5 Sep 2005 13:12:40 -0400

At 8:56 AM +0200 9/5/05, Paolo Bonzini wrote:
Jonathan Levi MD wrote:

Sir/Madam:

Recently, a shell script of mine terminated with an apparently erroneous error message. The following short script, followed by terminal output, illustrates the problem:

This is because the shell sees the single quote as a terminator of the other single quote.

Paolo, are you sure the problem is with the shell? Here's a slightly longer script with a commented ' in the midst of a sed command and a shell command, and also with line numbers; note that not only does sed fail, but it complains (by name) about the lack of a (nonexistent) file:

#!/bin/sh
# ScriptBrokenBySingleQuote.sh                               2
# Created by Jonathan Levi, M.D. on 9/5/05.                  3
str="Hello World"   # '                                      4
strj=${str/H/J}  && #  script works if you delete this '     5
echo ${strj/d/ds}   #                                        6
echo $str | sed 's/H/M/ # script works if you delete this '  7
    s/lo/low/'        #                                      8


drj2:jonathan jonathan$ ScriptBrokenBySingleQuote.sh
Jello Worlds
sed: can't read 7: No such file or directory
/Users/jonathan/bin/ScriptBrokenBySingleQuote.sh: line 8: unexpected EOF while looking for matching `'' /Users/jonathan/bin/ScriptBrokenBySingleQuote.sh: line 10: syntax error: unexpected end of file


However, the script works if only the ' at line 7 is deleted, while the ' at line 5 is retained:

#!/bin/sh
# ScriptBrokenBySingleQuote.sh                               2
# Created by Jonathan Levi, M.D. on 9/5/05.                  3
str="Hello World"   # '                                      4
strj=${str/H/J}  && #  script works if you delete this '     5
echo ${strj/d/ds}   #                                        6
echo $str | sed 's/H/M/ # script works if you delete this   7
    s/lo/low/'        #                                      8


drj2:jonathan jonathan$ ScriptBrokenBySingleQuote.sh
Jello Worlds
Mellow World

Jonathan




reply via email to

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