Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 340090

Summary: sys-apps/portage: substititution variables in env.d dont always work
Product: Portage Development Reporter: Rene Petro <redix>
Component: Core - ConfigurationAssignee: Portage team <dev-portage>
Status: RESOLVED WONTFIX    
Severity: normal    
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Rene Petro 2010-10-07 19:49:43 UTC
problem while using substitution variables ( $VAR  or ${VAR} ) in /etc/env.d
enviroment is incorrectly set

Reproducible: Always

Steps to Reproduce:
1. make /etc/env.d/99test file with content:
VAR1="variable1"
VAR2="$VAR1/variable2"
VAR3="${VAR1}/variable3"
2. run env-update && source /etc/profile
3. run env|grep VAR

Actual Results:  
VAR1=variable1
VAR3=${VAR1}/variable3
VAR2=VAR1/variable2 

Expected Results:  
VAR1=variable1
VAR3=variable1/variable3
VAR2=variable1/variable2 

problem is here in env_update.py :
        env_keys.sort()
        for k in env_keys:
                v = env[k]
                if v.startswith('$') and not v.startswith('${'):
                        outfile.write("export %s=$'%s'\n" % (k, v[1:]))
                else:
                        outfile.write("export %s='%s'\n" % (k, v)) 


shoul be :

#        env_keys.sort() # <- is this really needed ?
        for k in env_keys:
                v = env[k]
                if v.startswith('$') and not v.startswith('${'):
                        outfile.write("export %s=$'%s'\n" % (k, v[1:])) # <- weird, what if one use VAR2="$VAR1/dir1 $VAR1/dir2" ?
                else:
                        outfile.write("export %s=\"%s\"\n" % (k, v)) # <- now it is safe to use ${VAR} in any context
Comment 1 Zac Medico gentoo-dev 2010-10-08 13:22:43 UTC
It was never intended to work. Maybe you should use /etc/profile.d instead. There's some code at the bottom of /etc/profile that automatically sources /etc/profile.d/*.sh.
Comment 2 Brian Dolbec (RETIRED) gentoo-dev 2015-03-04 22:49:30 UTC
Closing due to age and last comment.