NetBSD Problem Report #39195
From jschauma@netmeister.org Wed Jul 23 02:05:30 2008
Return-Path: <jschauma@netmeister.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id 938FB63B907
for <gnats-bugs@gnats.NetBSD.org>; Wed, 23 Jul 2008 02:05:30 +0000 (UTC)
Message-Id: <20080723020529.A6011711A2@panix.netmeister.org>
Date: Tue, 22 Jul 2008 22:05:29 -0400 (EDT)
From: jschauma@netmeister.org
Reply-To: jschauma@netmeister.org
To: gnats-bugs@gnats.NetBSD.org
Subject: /bin/sh tilde expansion doesn't take place on 'export=~/foo'
X-Send-Pr-Version: 3.95
>Number: 39195
>Category: bin
>Synopsis: /bin/sh tilde expansion doesn't take place on 'export=~/foo'
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Jul 23 02:10:00 +0000 2008
>Closed-Date: Thu May 25 12:18:48 +0000 2017
>Last-Modified: Thu May 25 12:18:48 +0000 2017
>Originator: Jan Schaumann
>Release: NetBSD 4.0
>Organization:
>Environment:
System: NetBSD panix.netmeister.org 4.0 NetBSD 4.0 (PANIX-VC) #1: Sat Dec 22 22:16:02 EST 2007 root@juggler.panix.com:/misc2/obj/misc2/devel/netbsd/4.0/src/sys/arch/i386/compile/PANIX-VC i386
Architecture: i386
Machine: i386
>Description:
See http://mail-index.netbsd.org/tech-userlevel/2008/07/14/msg000879.html
On 14-Jul-08, at 3:00 PM, Jan Schaumann wrote:
>
> When exactly does /bin/sh's tilde expansion take place?
>
> $ /bin/sh -x
> $ export DIR=~/tmp
> + export DIR=~/tmp
> $ ls -ld $DIR
> + ls -ld ~/tmp
> ls: ~/tmp: No such file or directory
> $ cd
> + cd
> $ ls -ld tmp
> + ls -ld tmp
> drwx------ 2 jschauma users 512 Jul 4 21:37 tmp
> $ ^D
Greg Woods noted:
It works fine if the variable is set first without the "export":
15:14 [1] $ /bin/sh
$ foobar=~/tmp
$ echo $foobar
/home/most/woods/tmp
$ export foobar
$ echo $foobar
/home/most/woods/tmp
$ ^D15:15 [2] $
>How-To-Repeat:
/bin/sh
mkdir ~/tmp
export dir=~/tmp
ls -ld $dir
>Fix:
>Release-Note:
>Audit-Trail:
From: "Greg A. Woods; Planix, Inc." <woods@planix.ca>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/39195: /bin/sh tilde expansion doesn't take place on 'export=~/foo'
Date: Wed, 23 Jul 2008 12:33:51 -0400
On 22-Jul-08, at 10:10 PM, jschauma@netmeister.org wrote:
>> Number: 39195
>> Category: bin
>> Synopsis: /bin/sh tilde expansion doesn't take place on
>> 'export=~/foo'
>> Confidential: no
>> Severity: non-critical
>> Priority: low
>> Responsible: bin-bug-people
>> State: open
>> Class: sw-bug
>> Submitter-Id: net
>> Arrival-Date: Wed Jul 23 02:10:00 +0000 2008
>> Originator: Jan Schaumann
>> Release: NetBSD 4.0
>> Organization:
>
>> Environment:
>
>
> System: NetBSD panix.netmeister.org 4.0 NetBSD 4.0 (PANIX-VC) #1:
> Sat Dec 22 22:16:02 EST 2007 root@juggler.panix.com:/misc2/obj/misc2/
> devel/netbsd/4.0/src/sys/arch/i386/compile/PANIX-VC i386
> Architecture: i386
> Machine: i386
>> Description:
>
> See http://mail-index.netbsd.org/tech-userlevel/2008/07/14/msg000879.html
>
> On 14-Jul-08, at 3:00 PM, Jan Schaumann wrote:
>>
>> When exactly does /bin/sh's tilde expansion take place?
>>
>> $ /bin/sh -x
>> $ export DIR=~/tmp
>> + export DIR=~/tmp
>> $ ls -ld $DIR
>> + ls -ld ~/tmp
>> ls: ~/tmp: No such file or directory
>> $ cd
>> + cd
>> $ ls -ld tmp
>> + ls -ld tmp
>> drwx------ 2 jschauma users 512 Jul 4 21:37 tmp
>> $ ^D
>
> Greg Woods noted:
>
> It works fine if the variable is set first without the "export":
>
> 15:14 [1] $ /bin/sh
> $ foobar=~/tmp
> $ echo $foobar
> /home/most/woods/tmp
> $ export foobar
> $ echo $foobar
> /home/most/woods/tmp
> $ ^D15:15 [2] $
I also noted:
HOWEVER, from my cursory reading of the Single UNIX Specification it
would seem that /bin/sh is conforming as-is -- i.e. the tilde
character is only to be recognized and expanded if it is an unquoted
character at the beginning of a word (except in an assignment where
multiple tilde-prefixes can be used with subsequent ones recognized
after any unquoted colon character).
Further reading of SuS shows that the "assignment-like" behaviour of
"export" is defined, though perhaps somewhat poorly. In the
informative text section the following text appears:
IEEE Std 1003.1-2001/Cor 1-2002, item XCU/TC1/D6/6 is applied, adding
the following text to the end of the first paragraph of the
DESCRIPTION: ``If the name of a variable is followed by = word, then
the value of that variable shall be set to word.''. The reason for
this change is that the SYNOPSIS for export includes:
export name[=word]...
but the meaning of the optional ``= word'' is never explained in the
text.
So, I'm still somewhat confused (it appears this meaning kind of snuck
in by accident).
In any case the use of "word" here suggests that during expansion a
tilde should be recognized and expanded if it appears un-quoted at the
beginning of "word".
--
Greg A. Woods; Planix, Inc.
<woods@planix.ca>
State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Thu, 25 May 2017 12:18:48 +0000
State-Changed-Why:
This one is a "not a bug, won't fix".
The rules for tilde expansions are quite clear, and the place
where it was expected to work here is not one of them. Making
a ~ expansion happen in this context would also allow it in
other contexts when it is not desired - the expansions happen,
have to happen, before anyone has any idea that the command
involved is export (or local, or readonly which operate the same way.)
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.