Created
November 30, 2015 00:20
-
-
Save odeke-em/80c94e1e586cf88337c6 to your computer and use it in GitHub Desktop.
Env vars don't change within running program in various langs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
func cwd() string { | |
wd, _ := os.Getwd() | |
return wd | |
} | |
func envPwd() string { | |
return os.Getenv("PWD") | |
} | |
func main() { | |
fmt.Println(cwd()) | |
os.Chdir("/") | |
fmt.Println(cwd()) | |
os.Chdir(envPwd()) | |
fmt.Printf("pwdFromEnv: %s cwd: %s\n", envPwd(), cwd()) | |
os.Chdir("/") | |
fmt.Printf("pwdFromEnv: %s cwd: %s\n", envPwd(), cwd()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cwd() { | |
return process.cwd(); | |
} | |
function envPwd() { | |
return process.env['PWD'] || '/'; | |
} | |
console.log('cwd', cwd()); | |
process.chdir('/'); | |
console.log('new wd', cwd()); | |
process.chdir(envPwd()); | |
console.log('pwd %s cwd %s', envPwd(), cwd()); | |
process.chdir('/'); | |
console.log('pwd %s cwd %s', envPwd(), cwd()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
def cwd(): | |
return os.getcwd() | |
def envPwd(): | |
return os.environ.get('PWD') | |
def main(): | |
print('cwd', cwd()); | |
os.chdir('/'); | |
print('new wd', cwd()); | |
os.chdir(envPwd()); | |
print('pwd %s cwd %s'%(envPwd(), cwd())) | |
os.chdir('/'); | |
print('pwd %s cwd %s'%(envPwd(), cwd())) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
function envPwd { | |
echo $@ $PWD; | |
} | |
envPwd 'cwd ' | |
cd '/' | |
envPwd 'new wd ' | |
cd $OLDPWD | |
echo -e | |
envPwd 'cwd ' | |
cd '/' | |
envPwd 'new wd ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment