|
From: | Paolo Bonzini |
Subject: | Re: GNU sed Bug (Single Quotes in Comments Cause Errors) |
Date: | Mon, 05 Sep 2005 19:51:57 +0200 |
User-agent: | Mozilla Thunderbird 0.9 (Macintosh/20041103) |
#!/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
Have you noticed 7 is the first character after the ' ?
However, the script works if only the ' at line 7 is deleted, while the ' at line 5 is retained:
Because the comment at lines 4/5 are parsed by the shell, and run until the end of the input line. The # character at line 7 is in a quoted string, hence it is handed to sed literally together with the commands. Then sed looks in the quoted string and discards the comment.
Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |