bin/105078: sh(1) aborts on invalid substitution in a not-taken if statement

Ed Maste emaste at FreeBSD.org
Thu Nov 2 18:40:23 UTC 2006


>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 at 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:


More information about the freebsd-bugs mailing list