Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Question about inline code / incompatibility between FreeBSD sh and bash

2 views
Skip to first unread message

Garrett Cooper

unread,
Jun 19, 2008, 5:29:57 AM6/19/08
to bug-...@gnu.org
On Thu, Jun 19, 2008 at 2:12 AM, Garrett Cooper <yane...@gmail.com> wrote:
> Hi,
> Sorry for emailing this list, but neither the GNU indexed
> homepage nor the actual project page listed any other email address.
> I'm trying to determine whether or not this is an implicit bug or
> a feature of BSD bourne shell (in particular FreeBSD's sh):
> When I try and execute `portsnap fetch update' [1], things go
> through as the author intended. However, using `bash portsnap fetch
> update' I get the following error message:
>
> /usr/sbin/portsnap: portsnap: line 882: syntax error near unexpected
> token `newline'
> /usr/sbin/portsnap: portsnap: line 882: ` if !'
>
> The incompatible section of code (at least the one that bash
> barfs on -- I say that because there are a few similar sections IIRC)
> is:
>
> if !
> if ! [ -z "${EXTRACTPATH}" ]; then
> grep "^${EXTRACTPATH}" ${WORKDIR}/INDEX
> elif ! [ -z "${REFUSE}" ]; then
> grep -vE "${REFUSE}" ${WORKDIR}/INDEX
> else
> cat ${WORKDIR}/INDEX
> fi | tr '|' ' ' | while read FILE HASH; do
> echo ${PORTSDIR}/${FILE}
> if ! [ -r "${WORKDIR}/files/${HASH}.gz" ]; then
> echo "files/${HASH}.gz not found -- snapshot corrupt."
> return 1
> fi
> case ${FILE} in
> */)
> rm -rf ${PORTSDIR}/${FILE%/}
> mkdir -p ${PORTSDIR}/${FILE}
> tar -xzf ${WORKDIR}/files/${HASH}.gz \
> -C ${PORTSDIR}/${FILE}
> ;;
> *)
> rm -f ${PORTSDIR}/${FILE}
> tar -xzf ${WORKDIR}/files/${HASH}.gz \
> -C ${PORTSDIR} ${FILE}
> ;;
> esac
> done; then
>
> I'm pretty sure that the issue is because the code spans multiple
> lines and could be (typically) modularized out into a function in
> bash.
> So the question is, can anyone verify that either bash or
> FreeBSD's sh is correct, and/or verify whether or not there is a
> possible incompatibility with the POSIX spec for bourne shells in
> either camp?
> Thanks,
> -Garrett
>
> PS Please CC me as I'm not subscribed to bug-...@gnu.org.
>
> [1] A copy of portsnap can be found here:
> http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.sbin/portsnap/portsnap/portsnap.sh?rev=1.28;content-type=text%2Fplain

When I take the above code, combine remove the newline and make it into ...

if ! if ! [ -z "${EXTRACTPATH}" ]; then

... as well as line 951, the script is parsed properly.

The "problem" is reported at parse.y:3071, but I'm unsure how to trace
back the issue through the yacc code.

-Garrett


Garrett Cooper

unread,
Jun 19, 2008, 5:12:43 AM6/19/08
to bug-...@gnu.org

Garrett Cooper

unread,
Jun 19, 2008, 6:05:57 AM6/19/08
to bug-...@gnu.org
On Thu, Jun 19, 2008 at 2:29 AM, Garrett Cooper <yane...@gmail.com> wrote:
> On Thu, Jun 19, 2008 at 2:12 AM, Garrett Cooper <yane...@gmail.com> wrote:
>>
> When I take the above code, combine remove the newline and make it into ...
>
> if ! if ! [ -z "${EXTRACTPATH}" ]; then
>
> ... as well as line 951, the script is parsed properly.
>
> The "problem" is reported at parse.y:3071, but I'm unsure how to trace
> back the issue through the yacc code.

Correction: report_syntax_error in parse.y.
-Garrett


Andreas Schwab

unread,
Jun 21, 2008, 1:56:05 PM6/21/08
to Garrett Cooper, bug-...@gnu.org
"Garrett Cooper" <yane...@gmail.com> writes:

> Hi,
> Sorry for emailing this list, but neither the GNU indexed
> homepage nor the actual project page listed any other email address.
> I'm trying to determine whether or not this is an implicit bug or
> a feature of BSD bourne shell (in particular FreeBSD's sh):
> When I try and execute `portsnap fetch update' [1], things go
> through as the author intended. However, using `bash portsnap fetch
> update' I get the following error message:
>

> /usr/sbin/portsnap: portsnap: line 882: syntax error near unexpected
> token `newline'
> /usr/sbin/portsnap: portsnap: line 882: ` if !'
>
> The incompatible section of code (at least the one that bash
> barfs on -- I say that because there are a few similar sections IIRC)
> is:
>
> if !

POSIX does not allow a newline between ! and the command, see
<http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_10_02>.

Andreas.

--
Andreas Schwab, SuSE Labs, sch...@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."


0 new messages