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

export -p may output invalid variables

3 views
Skip to first unread message

Stephane Chazelas

unread,
May 9, 2008, 11:18:11 AM5/9/08
to bug-...@gnu.org, ba...@packages.debian.org
Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -g -O2 -Wall
uname output: Linux sc.homeunix.net 2.6.25-rc8 #1 PREEMPT Fri Apr 4 08:56:07 BST 2008 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.2
Patch Level: 33
Release Status: release

Description:
~$ env -i '1=a' sh -c 'export -p'
export 1="a"
export OLDPWD
export PWD="/home/chazelas"
export SHLVL="1"
~$ env -i '1=a' bash -c 'export -p'
declare -x 1="a"
declare -x OLDPWD
declare -x PWD="/home/chazelas"
declare -x SHLVL="1"
~$ env -i '1=a' sh -c 'export -p' | sh
sh: line 1: export: `1=a': not a valid identifier
~$ env -i '1=a' bash -c 'export -p' | bash
bash: line 1: declare: `1=a': not a valid identifier

ash/dash are also affected. zsh, pdksh, mksh, posh, ksh93 are not.


Repeat-By:
see above.

Fix:
only report about shell variables.


Chet Ramey

unread,
May 10, 2008, 10:28:54 PM5/10/08
to Stephane Chazelas, bug-...@gnu.org, ba...@packages.debian.org, chet....@case.edu
Stephane Chazelas wrote:

> Bash Version: 3.2
> Patch Level: 33
> Release Status: release
>
> Description:
> ~$ env -i '1=a' sh -c 'export -p'
> export 1="a"
> export OLDPWD
> export PWD="/home/chazelas"
> export SHLVL="1"
> ~$ env -i '1=a' bash -c 'export -p'
> declare -x 1="a"
> declare -x OLDPWD
> declare -x PWD="/home/chazelas"
> declare -x SHLVL="1"
> ~$ env -i '1=a' sh -c 'export -p' | sh
> sh: line 1: export: `1=a': not a valid identifier
> ~$ env -i '1=a' bash -c 'export -p' | bash
> bash: line 1: declare: `1=a': not a valid identifier

Thanks for the report. The right fix is to ignore words in the
environment that are not valid shell assignment statements. Bash
already does this for words without an `=', for instance.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Live Strong. No day but today.
Chet Ramey, ITS, CWRU ch...@case.edu http://cnswww.cns.cwru.edu/~chet/


0 new messages