Skip to main content
The 2024 Developer Survey results are live! See the results
17 events
when toggle format what by license comment
Jul 16 at 19:30 comment added majorgear @DennisWilliamson That worked great. Ty.
Jul 14 at 22:51 comment added Dennis Williamson @majorgear: Space separated: FOO=bar baz=qux myvar=someval bash -c 'somecommand someargs | somecommand2'
Jul 14 at 2:50 comment added majorgear how do you set more than one? Say 2 environment variables? are they space separated, comma separated, or other?
Apr 25, 2019 at 18:50 comment added mwag @DennisWilliamson, thanks for noticing that and asking in the other forum. When I run on 3.2.57(1)-release (x86_64-apple-darwin17) I get a blank, and when I run on 3.2.57(1)-release (x86_64-apple-darwin14) I get the warning + variable.
Apr 25, 2019 at 13:05 comment added Dennis Williamson I have asked a question about this on apple.stackexchange.com.
Apr 25, 2019 at 12:53 comment added Dennis Williamson @mwag: I wasn't invoking dyld either. It seems to automagically get invoked. What version of MacOS are you running and what does bash --version say? I just checked and the result that I reported above is because I was using Bash 5. When I use /bin/bash (Bash 3.2), I get no warning and a blank line is echoed (as if the variable were empty). The dynamic loader is doing something behind the scenes regardless.
Apr 25, 2019 at 2:54 comment added mwag @DennisWilliamson: I am not invoking dyld, I am invoking echo, and on my system, it does fail: running the exact, verbatim command DYLD_X=foox bash -c 'echo $DYLD_X', nothing at all gets echo'd (but it does if I use eval instead of bash -c)
Apr 25, 2019 at 2:24 comment added Dennis Williamson @mwag: I don't know anything about dyld ("the dynamic linker"), but it evidently watches for variables that start with DYLD_ and it recognizes a certain set of them but complains about ones it doesn't know about. The "fails" you refer to is specifically a warning message output by dyld: "dyld: warning, unknown environment variable: DYLD_X". Note that that is a warning, not an error, and the value of the variable is actually output.
Apr 24, 2019 at 22:49 comment added mwag Odd: on OSX, FOO_X=foox bash -c 'echo $FOO_X' works as expected but with specific var names it fails: DYLD_X=foox bash -c 'echo $DYLD_X' echos blank. both work using eval instead of bash -c
Mar 25, 2016 at 20:12 history rollback Dennis Williamson
Rollback to Revision 1
Mar 25, 2016 at 17:22 history edited Roman Pushkin CC BY-SA 3.0
Add example with accessing a variable.
Jan 22, 2016 at 19:07 comment added Pushpendre Note that if your command already has two levels of quotes then this method becomes extremely unsatisfactory because of quote hell. In that situation exporting in subshell is much better.
Mar 24, 2015 at 20:17 comment added ThorSummoner Note that if you need to run your somecommand as sudo, you need to pass sudo the -E flag to pass though variables. Because variables can introduce vulnerabilities. stackoverflow.com/a/8633575/1695680
Jun 1, 2012 at 19:49 vote accept MartyMacGyver
Jun 1, 2012 at 19:45 comment added Dennis Williamson @MartyMacGyver: None that I can think of. It won't work with curly braces either.
Jun 1, 2012 at 19:44 comment added MartyMacGyver This satisfies my criteria (one-liner without needing "export")... I take it there's no way to do this without calling "bash -c" (e.g., creative use of parentheses)?
Jun 1, 2012 at 19:39 history answered Dennis Williamson CC BY-SA 3.0