Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Nov 2006 18:31:12 GMT
From:      Ed Maste <emaste@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/105078: sh(1) aborts on invalid substitution in a not-taken if statement
Message-ID:  <200611021831.kA2IVCTB069784@freefall.freebsd.org>
Resent-Message-ID: <200611021840.kA2IeH9V071424@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         105078
>Category:       bin
>Synopsis:       sh(1) aborts on invalid substitution in a not-taken if statement
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 02 18:40:17 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Ed Maste
>Release:        FreeBSD 6.0-STABLE i386
>Organization:
FreeBSD
>Environment:
System: FreeBSD freefall.freebsd.org 6.0-STABLE FreeBSD 6.0-STABLE #0: Sat Dec 10 03:18:20 UTC 2005 kensmith@freefall.freebsd.org:/usr/obj/usr/src/sys/FREEFALL i386

>Description:
It seems our sh(1) attempts to evaluate variable substitutions inside of an if statement
even if the statement evaluates to false.

I discovered this with a shell script that encapsulated some Linux sh-isms inside of a
check based on uname -s, and our sh aborted on those statements.  That shell script was
using a substring of the form ${var:1:3}, but I've used an intentionally bogus
substitution of ${} in the example below.

For reference, I observed the same behaviour with NetBSD's sh.  My Debian box produced
no error.  (I'm not sure what sh variant it has installed as /bin/sh.)  Solaris 10 was
also silent (thanks rwatson for checking).

>How-To-Repeat:
$ /bin/sh -c 'if false; then x=${}; fi'
Syntax error: Bad substitution

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200611021831.kA2IVCTB069784>