Linked Questions

11 votes
2 answers
3k views

Bash: assignment of variable on same line not altering echo behavior [duplicate]

a=2 a=3 echo $a #prints 2 can someone explain why would anyone use the above code in line-2. a=3 will be ignored as there is no "enter" after it. But I saw it in script like above and not sure ...
user5803214's user avatar
5 votes
2 answers
12k views

Variable value doesn't change in bash script [duplicate]

Running the following code: a=one; echo $a a=two echo $a a=three echo $a >$a results in one one and a created file with name "one" with content "one" Why the variable didn't change to two at ...
Petar D.'s user avatar
  • 317
6 votes
2 answers
10k views

How to start a command in bash with multiple environment variables set [duplicate]

With one environment variable it goes like: bash$> foo=1 echo "$foo" 1 [EDIT: as noted below, even that won't work but worked only because $foo was previously set by some other trial. Should had ...
zimon's user avatar
  • 171
1 vote
1 answer
3k views

Bash: inject variable in command, that sets an env variable [duplicate]

With bash, I'm trying to set environment variables for a given command by injecting another variable before running said command: It's easier to describe that with an example: setHELLO="HELLO=42&...
Nicolas Marshall's user avatar
2 votes
2 answers
760 views

In Bash, why `x=100 echo $x` doesn't print anything? [duplicate]

I saw codes like this: fqdn='computer1.daveeddy.com' IFS=. read hostname domain tld <<< "$fqdn" echo "$hostname is in $domain.$tld" # => "computer1 is in daveeddy.com" I think it works ...
Hanfei Sun's user avatar
  • 47.3k
5 votes
2 answers
278 views

Why does "A=3; A=4 echo $A" produce 3 (instead of 4) in Bash? [duplicate]

If I understand correctly, the syntax Var=<something> command should run the command after setting Var to "something". Then why does "A=3; A=4 echo $A" produces 3 in my bash?
zell's user avatar
  • 10.3k
0 votes
2 answers
1k views

assign and expand shell variable in same command line [duplicate]

I want to assign one or multiple variables at the beginning of a command line in my shell to reuse it in the command invocation. I'm confused of how my shell behaves and want to understand what is ...
Thomas Koch's user avatar
  • 2,941
0 votes
2 answers
1k views

Inline BASH variable, can't get the command to receive it [duplicate]

Why doesn't this work? HELLO=WORLD echo $HELLO In my shell it outputs
Fredster's user avatar
  • 776
7 votes
0 answers
800 views

Assign and use of a variable in the same subshell [duplicate]

I was doing something very simple like: v=5 echo "$v" and expected it to print 5. However, it does not. The value that was just set is not available for the next command. I recently learnt that "In ...
fedorqui's user avatar
  • 293k
3 votes
1 answer
308 views

Why doesn't ''var=value echo $var'' emit value? [duplicate]

Wanted to validate my understanding of why these situations behave differently: I think #1 happens because the assignment and echo run as a single command in the shell and $SOME_VAR is not set when ...
Ankur Agarwal's user avatar
0 votes
1 answer
285 views

Why do bash environment variables differ in shell versus node? [duplicate]

Run these commands in Bash: NODE_ENV=production echo $NODE_ENV outputs "" NODE_ENV=production && echo $NODE_ENV outputs "production" export NODE_ENV=production && echo $NODE_ENV ...
Ivan Yan's user avatar
  • 475
2 votes
1 answer
486 views

Bash: 'echo' not outputting variable defined on same line [duplicate]

This echo call outputs the variable: $ FOO="bar" eval 'echo foo: "$FOO"' foo: bar But this one does not: $ FOO="bar" echo foo: "$FOO" foo: Why is that? I'm pretty sure I have the single and double ...
jlucktay's user avatar
  • 442
0 votes
1 answer
280 views

How to dynamically compute value of a variable and use it in a command? [duplicate]

Reducing what I'm trying to do to a simple example: env temp=`pwd` echo "$temp" I get this message: temp: Undefined variable. How do I make it work (in a shell-agnostic way)? I'm expecting the ...
JLB's user avatar
  • 3
2 votes
1 answer
72 views

Why environment variables aren't being passed in a single command [duplicate]

In bash, I can pass an environment variable to a single command in the following way: KEY=VAL <command> However, I don't understand why the following doesn't work: KEY=VAL echo $KEY While this ...
Wahaj Ali's user avatar
  • 4,113
0 votes
1 answer
75 views

How python can execute shell command with env [duplicate]

Basically, os.system() can execute shall commands, such as: os.system("echo $A") It will work well and output value environment variable A. But this seems to not work: os.system("A=b ...
TieDad's user avatar
  • 10.1k

15 30 50 per page