Date: Wed, 10 Jul 2002 13:20:05 -0700 (PDT) From: Giorgos Keramidas <keramida@FreeBSD.org> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/40386: Parsing problem with /bin/sh Message-ID: <200207102020.g6AKK5WW037401@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/40386; it has been noted by GNATS.
From: Giorgos Keramidas <keramida@FreeBSD.org>
To: Chet Ramey <chet@po.cwru.edu>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/40386: Parsing problem with /bin/sh
Date: Wed, 10 Jul 2002 22:54:25 +0300
On 2002-07-09 10:38 +0000, Chet Ramey wrote:
> There is a parsing problem with /bin/sh. The attached script should
> not work without a backslash at the end of the first line, but sh
> accepts it nevertheless.
> quartz(2)# cat x1
> awk '{print 12345}' </dev/null
> || exit 1
> quartz(2)# ./sh ./x1
> quartz(2)# /bin/bash ./x1
> ./x1: line 2: syntax error near unexpected token `||'
> ./x1: line 2: ` || exit 1'
Just to clarify a bit. There is nothing wrong with sh(1) here. The
first line is not continued to the second one with a backslash, and it
runs as expected. The second line is faulty though, because sh(1)
attempts to parse it as a complete command and it (correctly) fails.
> This faulty syntax is used in /usr/libexec/locate.mklocatedb
> (/usr/src/usr.bin/locate/locate/mklocatedb.sh).
This is a problem :/
How does the following change look?
%%%
Index: mklocatedb.sh
===================================================================
RCS file: /home/ncvs/src/usr.bin/locate/locate/mklocatedb.sh,v
retrieving revision 1.12
diff -u -r1.12 mklocatedb.sh
--- mklocatedb.sh 23 Jun 2002 00:57:17 -0000 1.12
+++ mklocatedb.sh 10 Jul 2002 19:53:20 -0000
@@ -75,17 +75,17 @@
# This scheme avoid large temporary files in /tmp
$code $bigrams > $filelist || exit 1
- locate -d $filelist / | $bigram | $sort -nr | head -128 |
- awk '{if (/^[ ]*[0-9]+[ ]+..$/) {printf("%s",$2)} else {exit 1}}' > $bigrams
- || exit 1
+ locate -d $filelist / | $bigram | $sort -nr | head -128 | \
+ awk '{if (/^[ ]*[0-9]+[ ]+..$/) {printf("%s",$2)} else {exit 1}}' \
+ > $bigrams || exit 1
locate -d $filelist / | $code $bigrams || exit 1
exit
else
if $sortcmd $sortopt > $filelist; then
- $bigram < $filelist | $sort -nr |
- awk '{if (/^[ ]*[0-9]+[ ]+..$/) {printf("%s",$2)} else {exit 1}}' > $bigrams
- || exit 1
+ $bigram < $filelist | $sort -nr | \
+ awk '{if (/^[ ]*[0-9]+[ ]+..$/) {printf("%s",$2)} else {exit 1}}' \
+ > $bigrams || exit 1
$code $bigrams < $filelist || exit 1
else
echo "`basename $0`: cannot build locate database" >&2
%%%
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200207102020.g6AKK5WW037401>
