How to save and echo variables in a Makefile? [duplicate] - bash

This question already has answers here:
How do I use shell variables in Makefile actions?
(2 answers)
Using bash variables in Makefile
(3 answers)
Closed 5 months ago.
I have a simple makefile
SHELL := /bin/bash
test:
VAR='test' && echo ${VAR};
However, this does not exhibit the same behavior as typing this command into a normal shell, and it doesn't echo anything. Not sure what I am missing.

Related

Trying to run multiple processes in bash only executes one time [duplicate]

This question already has answers here:
Brace expansion with variable? [duplicate]
(6 answers)
how to use variables with brace expansion [duplicate]
(2 answers)
Closed 2 years ago.
I have the following in my bash file:
echo "Spawning $1 processes"
for i in {1..$1}
do
(go run loadgen.go $2 &)
echo "done."
done
However, I can only seem to get my go file to execute once. I know that they're started in the background, but each of my go files should append to the same log file (I can reproduce this by running my bash script multiple times). Am I doing something wrong to get this to iterate multiple times?

Difference in "sourcing" from a file in bash [duplicate]

This question already has answers here:
Can a shell script set environment variables of the calling shell? [duplicate]
(20 answers)
What does the command 'source' do?
(1 answer)
What is the difference between using `sh` and `source`?
(5 answers)
Closed 3 years ago.
What is the difference between the following two commands to source a file and then print the env variables?
sh -c . envvars.sh; env
And:
./envvars.sh; env
More specifically, what do the following do:
". envvars.sh" vs. "./envvars.sh"
And:
"sh -c envvars.sh" and "./envvars.sh"

Bash -Bad substitution error when evaluating two env variables [duplicate]

This question already has answers here:
creating environment variable with user-defined name - indirect variable expansion
(1 answer)
Dynamic variable names in Bash
(19 answers)
Is it possible to build variable names from other variables in bash? [duplicate]
(7 answers)
Closed 3 years ago.
This is my script:
#!/bin/bash
AREA="DEV"
DEV_AREA_USER="DevAdmin"
TEST_AREA_USER="TestAdmin"
TEST=${$AREA_AREA_USER}
echo ${TEST}
Result: Bad substitution error. Expected result: DevAdmin
How to fix this? I do not want to create a new variable because there are 75 such variables and 75 files to edit. The lesser the better...

bash bad substitution - access an environment variable from another [duplicate]

This question already has answers here:
Bash - variable variables [duplicate]
(4 answers)
Dynamic variable names in Bash
(19 answers)
How to use a variable's value as another variable's name in bash [duplicate]
(6 answers)
Reference an appended variable?
(3 answers)
Closed 5 years ago.
How can I access an environment variable from another? I have the following in my shell
#!/usr/bin/env bash
set -x
export A_version=1.0.0
component=A
echo ${${component}_version}}
the bash script after the run gives me
temp.sh: line 9: ${${component}_version}}: bad substitution
You can use eval to do this. Here is a working version of your script that prints 1.0.0:
export A_version=1.0.0
component=A
eval "echo \$${component}_version"
For more information, see this page:
http://tldp.org/LDP/abs/html/ivr.html
Update: A safer way to do the same thing in Bash would be:
export A_version=1.0.0
component=A
var=${component}_version; echo "${!var}"
Note that you have to run this script with bash, not sh.

Is it mandatory to use #!/bin/bash even inside bash subshell [duplicate]

This question already has answers here:
Writing a Bash script without the shebang line
(2 answers)
Bash script execution with and without shebang in Linux and BSD
(2 answers)
Closed 5 years ago.
If after logging into my system I type: bash (to use bash subshell) and then try to run a bash script (e.g. example.sh), then does it matter if I do not put #!/bin/bash as the first line of the script or it is fine since I am already inside bash subshell?

Resources