From owner-freebsd-bugs Wed Jul 10 13:20:14 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D996537B405 for ; Wed, 10 Jul 2002 13:20:05 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7B63743E42 for ; Wed, 10 Jul 2002 13:20:05 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g6AKK5JU037402 for ; Wed, 10 Jul 2002 13:20:05 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g6AKK5WW037401; Wed, 10 Jul 2002 13:20:05 -0700 (PDT) Date: Wed, 10 Jul 2002 13:20:05 -0700 (PDT) Message-Id: <200207102020.g6AKK5WW037401@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Giorgos Keramidas Subject: Re: bin/40386: Parsing problem with /bin/sh Reply-To: Giorgos Keramidas Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/40386; it has been noted by GNATS. From: Giorgos Keramidas To: Chet Ramey 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}' || 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