Questions tagged [indirection]
The indirection tag has no summary.
9 questions
5
votes
2
answers
442
views
How to do indirect variable substitution in a GNU Makefile?
In the shell I can do
$ a=b b=c; eval echo \$$a
c
How do I do the same with GNU Make's $(eval) function?
$ cat Makefile
a=b
b=c
x:; echo {What goes here in order to get:}
$ make
c
1
vote
4
answers
168
views
Synthetic Variables in Bash (was: How to address a variable ceated with indirection) [duplicate]
Sorry, that was all too confusing, (my bad)
Let me try to explain again, but with a more simple example:
#define a new var and export it to the "env":
export VAR_ONE=thisIsVarOne
# check if ...
0
votes
1
answer
164
views
Why don't I need to use bash indirection with string substitution?
One challenging thing I've encountered in bash scripting is using variable expansion in a recursive way.
However, I was able to figure out [through ChatGPT] that I could use indirect subsitution to ...
0
votes
2
answers
707
views
Concatenating string to form an existing variable name and working within array enclosure format
#!/bin/bash
mat_1=(ServerAB ServerFR ServerPE ServerAM ServerHU)
st="mat_1";
indirect_var='${'${st}'[@]}'
#(Please, see the "--Desired Ouput Section--" in comments)
#----- What ...
4
votes
4
answers
1k
views
Command substitution in quotes cannot be used to call the variable
Say:
variable="Something that it holds"
then
echo "$variable" will output: Something that it holds
But say I also do:
var2="variable";
echo "\$$(echo $var2)"
...
1
vote
3
answers
360
views
Indirect access in bash arrays
I am trying to do the following indirect task:
host_1=(192.168.0.100 user1 pass1)
host_2=(192.168.0.101 user2 pass2)
hostlist=( "host_1" "host_2" )
for item in ${hostlist[@]}; do
...
4
votes
4
answers
2k
views
zsh testing existence of a key in an associative array via indirect expansion
So I know that you can test for the existence of a regular parameter via indirect expansion by doing something like:
foo=1
bar=foo
(( ${(P)+bar} )) && print "$bar exists"
And I know you can ...
2
votes
2
answers
456
views
How many levels of indirection can I apply in Bash?
In bash, I understand we can have variable indirect expansion via two ways:
Using declare: declare -n foo=bar
Using the ${!..} expansion.
We can combine both:
declare -n foo=SHELL
bar=foo
echo ${!bar}...
2
votes
1
answer
114
views
How to access further members of an array when using bash variable indirection?
Consider the following example, it seems it's working fine with the index 0:
$ a1=(1 2 3)
$ a2=(a b c)
$ for x in a1 a2; do echo "${!x}"; done
1
a
$ for x in a1 a2; do echo "${!x[0]}"; done
1
a
...