Linked Questions
10 questions linked to/from What is this shell/Bash syntax: someVariable=someValue someCommand
14
votes
3
answers
4k
views
Why doesn't bash expand this variable when I prefix a command with a "one time variable assignment" [duplicate]
If I run this bash command and prefix the statement, so that the variable fruit should exist, but only for the duration of this command:
$ fruit=apple echo $fruit
$
The result is an empty line. why?
...
10
votes
2
answers
43k
views
passing env variables to commands in bash [duplicate]
I have this sample bash command:
FILE='/tmp/1.txt' echo "file: $FILE"
and the output is:
file:
Why the output doesn't contain defined earlier variable FILE?
10
votes
4
answers
2k
views
Is it shell portable to run a command on the same line after variable assignment?
Is there any standard that covers the portability of running a command after variable assignment on the same line?
APPLE="cider" echo hi
How portable is something like that? Where will it work and ...
0
votes
3
answers
6k
views
Why cat command doesn't use its command environment? [duplicate]
AFAIK, cat is an external command and it forks off a new process when executed, just like sh -c or executing a script. With that said I expect cat to use its command environment as it is used by ...
0
votes
1
answer
1k
views
In bash, why is `SHELL=/bin/sh lesspipe"` gramatically correct? [duplicate]
On Ubuntu-like linux, the default .bashrc file contains a line:
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
Then why is SHELL=/bin/sh lesspipe grammatically correct? What ...
2
votes
3
answers
304
views
How come when I change an ENV variable and echo it in the same command, I don't see the new value? [duplicate]
When I run PATH=abc:$PATH echo $PATH, I get the old value for PATH, not abc:PATH
Why is this? How can I get abc:$PATH?
Edit:
How about for PATH=/mybin:$PATH which python if /mybin has a python ...
2
votes
1
answer
1k
views
Why does an inline variable definition work but a previous line does not for an aws command? [duplicate]
When I run this command:
https_proxy=http://myproxy.com/ aws [aws-param]
the proxy is picked up by the aws command line tool.
However - when I do this:
https_proxy=http://myproxy.com/
aws [aws-...
0
votes
1
answer
104
views
Setting environment variable before program name [duplicate]
I have come across commands like this:
CC=gcc ./configure
What is the effect of it exactly?
Is it identical with
export CC=gcc
./configure
?
Does the variable CC continue to exist after ...
0
votes
1
answer
61
views
What happens when we run var=3 command [duplicate]
Below I run what I expected to be an invalid command: var=3 date, which in fact isn't.
$ var=3 date
Sun May 26 17:10:22 UTC 2019
$ echo $?
0
But the variable wasn't assigned the value 3:
$ echo $var
...
1
vote
4
answers
593
views
Assignment: expression or command?
In Bash and Posix shells, there are many forms of commands, and an assignment is a form of command (specifically a simple command) if I am correct.
However let can be used in front of an assignment, ...