I think I'm having a massive brainfart. I would expect
env foo=bar echo $foo
...to print bar
, but I get an empty line instead. Wat.
The same happens if I use the bash syntax:
foo=bar echo $foo
I think I'm having a massive brainfart. I would expect
env foo=bar echo $foo
...to print bar
, but I get an empty line instead. Wat.
The same happens if I use the bash syntax:
foo=bar echo $foo
A similar question was answered recently: the symbols are evaluated in the line before the symbol is defined in this line, making it necessary to split the definition and use of the symbols to separate lines.
Prompted by a comment, you could have done this:
foo=bar bash -c 'echo $foo'
which first assigns a value to foo
and passes that into a new process as an environment variable where it can be printed.
You can read more about it in POSIX Shell Command Language Token recognition.
Following up from @mikeserv comment:
The shell shall read its input in terms of lines from a file, from a terminal in the case of an interactive shell, or from a string in the case of sh -c or system().
Once a token is delimited, it is categorized as required by the grammar in Shell Grammar.
env foo=bar bash -c 'echo $foo'
– badp Nov 09 '15 at 09:49@username...comment
the user you specify will get a little message letting them know you were talking to them. well, they will if its thread-relevant. – mikeserv Nov 09 '15 at 10:18luit.c
and i think i can just changesetup_io(){ ... ;fnctl(0, [GS]ETFL, 0);...}
to do2
for the first argument. well, i guess thecopyTermios()
andsetRawTermios()
functions might need a little modification as well, but it should be simple, i think. therc = (return)
for every line seems strange - but i'm no C programmer either. is that your thing or was that inherited? and if your blanks comment is referring to"${set_null_var:=new val and $(echo other stuff)}"
you're mostly safe w/ anything. some shells will do weird stuff with}
. – mikeserv Nov 09 '15 at 10:31