bash for loop with unknown array
I need to execute a for loop over the elements in array edg_cdi, but I know it is that array just because my input parameter is chosen='cdi'. If it was chosen='cdt' (or many others) the selected array would be different.
chosen='cdi'
edg_cdi=('40' '46' '37' '43')
edg_cdt=('69' '24' '177' '25')
string='edg_'
wholename=$string$chosen
for i in "${ WHAT_TO_WRITE_HERE [@]}"
do
echo $i
done
The desired output is four echos:
40
46
37
43
bash array
add a comment |
I need to execute a for loop over the elements in array edg_cdi, but I know it is that array just because my input parameter is chosen='cdi'. If it was chosen='cdt' (or many others) the selected array would be different.
chosen='cdi'
edg_cdi=('40' '46' '37' '43')
edg_cdt=('69' '24' '177' '25')
string='edg_'
wholename=$string$chosen
for i in "${ WHAT_TO_WRITE_HERE [@]}"
do
echo $i
done
The desired output is four echos:
40
46
37
43
bash array
when you say the "selected array would be different" you mean an array with different data or a different type, like a simple variable? Anyway for the code you provide for cycle substitute "WHAT_TO_WRITE_HERE" with ${wholename[@]}
– AtomiX84
Jan 22 at 14:20
@Pimp Juice IT. The issue is I don't know the variable name. After knowing chosen='cdi', I can get wholename='edg_cdi'. But "${wholename[@]}" won't work.
– Uxio
Jan 22 at 15:56
@AtomiX84 The output of for i in "${wholename[@]}" is wrong: It's edg_cdi, when it shoud be 40 46 37 43.
– Uxio
Jan 22 at 15:57
This question is maybe a duplicated of stackoverflow.com/questions/10820343/…. Anyway I have fixed your code using the accepted answer there and it works.
– user1330614
Jan 22 at 18:39
add a comment |
I need to execute a for loop over the elements in array edg_cdi, but I know it is that array just because my input parameter is chosen='cdi'. If it was chosen='cdt' (or many others) the selected array would be different.
chosen='cdi'
edg_cdi=('40' '46' '37' '43')
edg_cdt=('69' '24' '177' '25')
string='edg_'
wholename=$string$chosen
for i in "${ WHAT_TO_WRITE_HERE [@]}"
do
echo $i
done
The desired output is four echos:
40
46
37
43
bash array
I need to execute a for loop over the elements in array edg_cdi, but I know it is that array just because my input parameter is chosen='cdi'. If it was chosen='cdt' (or many others) the selected array would be different.
chosen='cdi'
edg_cdi=('40' '46' '37' '43')
edg_cdt=('69' '24' '177' '25')
string='edg_'
wholename=$string$chosen
for i in "${ WHAT_TO_WRITE_HERE [@]}"
do
echo $i
done
The desired output is four echos:
40
46
37
43
bash array
bash array
edited Jan 22 at 19:12
Uxio
asked Jan 22 at 13:50
UxioUxio
153
153
when you say the "selected array would be different" you mean an array with different data or a different type, like a simple variable? Anyway for the code you provide for cycle substitute "WHAT_TO_WRITE_HERE" with ${wholename[@]}
– AtomiX84
Jan 22 at 14:20
@Pimp Juice IT. The issue is I don't know the variable name. After knowing chosen='cdi', I can get wholename='edg_cdi'. But "${wholename[@]}" won't work.
– Uxio
Jan 22 at 15:56
@AtomiX84 The output of for i in "${wholename[@]}" is wrong: It's edg_cdi, when it shoud be 40 46 37 43.
– Uxio
Jan 22 at 15:57
This question is maybe a duplicated of stackoverflow.com/questions/10820343/…. Anyway I have fixed your code using the accepted answer there and it works.
– user1330614
Jan 22 at 18:39
add a comment |
when you say the "selected array would be different" you mean an array with different data or a different type, like a simple variable? Anyway for the code you provide for cycle substitute "WHAT_TO_WRITE_HERE" with ${wholename[@]}
– AtomiX84
Jan 22 at 14:20
@Pimp Juice IT. The issue is I don't know the variable name. After knowing chosen='cdi', I can get wholename='edg_cdi'. But "${wholename[@]}" won't work.
– Uxio
Jan 22 at 15:56
@AtomiX84 The output of for i in "${wholename[@]}" is wrong: It's edg_cdi, when it shoud be 40 46 37 43.
– Uxio
Jan 22 at 15:57
This question is maybe a duplicated of stackoverflow.com/questions/10820343/…. Anyway I have fixed your code using the accepted answer there and it works.
– user1330614
Jan 22 at 18:39
when you say the "selected array would be different" you mean an array with different data or a different type, like a simple variable? Anyway for the code you provide for cycle substitute "WHAT_TO_WRITE_HERE" with ${wholename[@]}
– AtomiX84
Jan 22 at 14:20
when you say the "selected array would be different" you mean an array with different data or a different type, like a simple variable? Anyway for the code you provide for cycle substitute "WHAT_TO_WRITE_HERE" with ${wholename[@]}
– AtomiX84
Jan 22 at 14:20
@Pimp Juice IT. The issue is I don't know the variable name. After knowing chosen='cdi', I can get wholename='edg_cdi'. But "${wholename[@]}" won't work.
– Uxio
Jan 22 at 15:56
@Pimp Juice IT. The issue is I don't know the variable name. After knowing chosen='cdi', I can get wholename='edg_cdi'. But "${wholename[@]}" won't work.
– Uxio
Jan 22 at 15:56
@AtomiX84 The output of for i in "${wholename[@]}" is wrong: It's edg_cdi, when it shoud be 40 46 37 43.
– Uxio
Jan 22 at 15:57
@AtomiX84 The output of for i in "${wholename[@]}" is wrong: It's edg_cdi, when it shoud be 40 46 37 43.
– Uxio
Jan 22 at 15:57
This question is maybe a duplicated of stackoverflow.com/questions/10820343/…. Anyway I have fixed your code using the accepted answer there and it works.
– user1330614
Jan 22 at 18:39
This question is maybe a duplicated of stackoverflow.com/questions/10820343/…. Anyway I have fixed your code using the accepted answer there and it works.
– user1330614
Jan 22 at 18:39
add a comment |
2 Answers
2
active
oldest
votes
You can use variable indirection with a proper array (unlike @user1330614's answer, which fakes an array with a plain variable). The tricky thing is that you have to include the array element (or [@]
for all elements) in the variable you're indirecting through. Like this:
edg_cdi=('40' '46' '37' '43')
wholename="edg_cdi" # Same value original code generates
wholearray="${wholename}[@]" # This includes the array name AND "[@]"
for i in "${!wholearray}"; do
#...etc
To get e.g. the n'th element of the array, you could use something like:
n=3 # The element number we want
wholename_n="${wholename}[n]" # Note that n does not have a $; it won't be resolved until use
dosomethingwith "${!wholename_n}" # this resolves n and gets the 3rd element
n=2
dosomethingwith "${!wholename_n}" # this re-resolves n and gets the 2nd element
1
Now this is the answer! I was going to publish a solution based ondeclare -p
. I thought it was decent, I still do; but yours is so much better there's no point in publishing my inferior one. My test array is likeedg_cdi=('normal' 'with space' 'double"quote' "single'quote" $'new-n-line' 'backslash')
, your code handles it flawlessly. Good job!
– Kamil Maciorowski
Jan 22 at 20:26
Additional reading on the topic with further examples and explanation for those that need even additional clarity perhaps..... Indirect References and Indirect variable references - the new way
– Pimp Juice IT
Jan 26 at 16:53
add a comment |
Your code should look like this
chosen='cdi'
edg_cdi="40 46 37 43"
edg_cdt="69 24 177 25"
string='edg_'
wholename=$string$chosen
for i in ${!wholename}
do
echo $i
done
As explained here
@Uxio Here's another related post that gives more detail about Variable Indirection: stackoverflow.com/questions/8515411/… too.
– Pimp Juice IT
Jan 22 at 18:52
@user1330614 Thank you for your reply, but, I think it is not working properly: The output of this answer is a single row: '40 46 37 43', a single echo. I need $i to be 40, then 46, then 37 and then 43. In this solution, edg_cdi is treated as a single string, but its required to be a set (array) of four independent elements, where the for loop can process independently.
– Uxio
Jan 22 at 19:09
I've tested the code myself and it outputs 40 46 37 and 43 in separated rows.
– user1330614
Jan 22 at 19:15
Make sure you don't enclose ${!wholename} between ""
– user1330614
Jan 22 at 19:18
@user1330614 Oh, sorry! True! Regards, thank you for your help.
– Uxio
Jan 22 at 19:20
|
show 2 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1397027%2fbash-for-loop-with-unknown-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use variable indirection with a proper array (unlike @user1330614's answer, which fakes an array with a plain variable). The tricky thing is that you have to include the array element (or [@]
for all elements) in the variable you're indirecting through. Like this:
edg_cdi=('40' '46' '37' '43')
wholename="edg_cdi" # Same value original code generates
wholearray="${wholename}[@]" # This includes the array name AND "[@]"
for i in "${!wholearray}"; do
#...etc
To get e.g. the n'th element of the array, you could use something like:
n=3 # The element number we want
wholename_n="${wholename}[n]" # Note that n does not have a $; it won't be resolved until use
dosomethingwith "${!wholename_n}" # this resolves n and gets the 3rd element
n=2
dosomethingwith "${!wholename_n}" # this re-resolves n and gets the 2nd element
1
Now this is the answer! I was going to publish a solution based ondeclare -p
. I thought it was decent, I still do; but yours is so much better there's no point in publishing my inferior one. My test array is likeedg_cdi=('normal' 'with space' 'double"quote' "single'quote" $'new-n-line' 'backslash')
, your code handles it flawlessly. Good job!
– Kamil Maciorowski
Jan 22 at 20:26
Additional reading on the topic with further examples and explanation for those that need even additional clarity perhaps..... Indirect References and Indirect variable references - the new way
– Pimp Juice IT
Jan 26 at 16:53
add a comment |
You can use variable indirection with a proper array (unlike @user1330614's answer, which fakes an array with a plain variable). The tricky thing is that you have to include the array element (or [@]
for all elements) in the variable you're indirecting through. Like this:
edg_cdi=('40' '46' '37' '43')
wholename="edg_cdi" # Same value original code generates
wholearray="${wholename}[@]" # This includes the array name AND "[@]"
for i in "${!wholearray}"; do
#...etc
To get e.g. the n'th element of the array, you could use something like:
n=3 # The element number we want
wholename_n="${wholename}[n]" # Note that n does not have a $; it won't be resolved until use
dosomethingwith "${!wholename_n}" # this resolves n and gets the 3rd element
n=2
dosomethingwith "${!wholename_n}" # this re-resolves n and gets the 2nd element
1
Now this is the answer! I was going to publish a solution based ondeclare -p
. I thought it was decent, I still do; but yours is so much better there's no point in publishing my inferior one. My test array is likeedg_cdi=('normal' 'with space' 'double"quote' "single'quote" $'new-n-line' 'backslash')
, your code handles it flawlessly. Good job!
– Kamil Maciorowski
Jan 22 at 20:26
Additional reading on the topic with further examples and explanation for those that need even additional clarity perhaps..... Indirect References and Indirect variable references - the new way
– Pimp Juice IT
Jan 26 at 16:53
add a comment |
You can use variable indirection with a proper array (unlike @user1330614's answer, which fakes an array with a plain variable). The tricky thing is that you have to include the array element (or [@]
for all elements) in the variable you're indirecting through. Like this:
edg_cdi=('40' '46' '37' '43')
wholename="edg_cdi" # Same value original code generates
wholearray="${wholename}[@]" # This includes the array name AND "[@]"
for i in "${!wholearray}"; do
#...etc
To get e.g. the n'th element of the array, you could use something like:
n=3 # The element number we want
wholename_n="${wholename}[n]" # Note that n does not have a $; it won't be resolved until use
dosomethingwith "${!wholename_n}" # this resolves n and gets the 3rd element
n=2
dosomethingwith "${!wholename_n}" # this re-resolves n and gets the 2nd element
You can use variable indirection with a proper array (unlike @user1330614's answer, which fakes an array with a plain variable). The tricky thing is that you have to include the array element (or [@]
for all elements) in the variable you're indirecting through. Like this:
edg_cdi=('40' '46' '37' '43')
wholename="edg_cdi" # Same value original code generates
wholearray="${wholename}[@]" # This includes the array name AND "[@]"
for i in "${!wholearray}"; do
#...etc
To get e.g. the n'th element of the array, you could use something like:
n=3 # The element number we want
wholename_n="${wholename}[n]" # Note that n does not have a $; it won't be resolved until use
dosomethingwith "${!wholename_n}" # this resolves n and gets the 3rd element
n=2
dosomethingwith "${!wholename_n}" # this re-resolves n and gets the 2nd element
edited Jan 22 at 20:10
Kamil Maciorowski
28.1k156185
28.1k156185
answered Jan 22 at 19:47
Gordon DavissonGordon Davisson
26k44350
26k44350
1
Now this is the answer! I was going to publish a solution based ondeclare -p
. I thought it was decent, I still do; but yours is so much better there's no point in publishing my inferior one. My test array is likeedg_cdi=('normal' 'with space' 'double"quote' "single'quote" $'new-n-line' 'backslash')
, your code handles it flawlessly. Good job!
– Kamil Maciorowski
Jan 22 at 20:26
Additional reading on the topic with further examples and explanation for those that need even additional clarity perhaps..... Indirect References and Indirect variable references - the new way
– Pimp Juice IT
Jan 26 at 16:53
add a comment |
1
Now this is the answer! I was going to publish a solution based ondeclare -p
. I thought it was decent, I still do; but yours is so much better there's no point in publishing my inferior one. My test array is likeedg_cdi=('normal' 'with space' 'double"quote' "single'quote" $'new-n-line' 'backslash')
, your code handles it flawlessly. Good job!
– Kamil Maciorowski
Jan 22 at 20:26
Additional reading on the topic with further examples and explanation for those that need even additional clarity perhaps..... Indirect References and Indirect variable references - the new way
– Pimp Juice IT
Jan 26 at 16:53
1
1
Now this is the answer! I was going to publish a solution based on
declare -p
. I thought it was decent, I still do; but yours is so much better there's no point in publishing my inferior one. My test array is like edg_cdi=('normal' 'with space' 'double"quote' "single'quote" $'new-n-line' 'backslash')
, your code handles it flawlessly. Good job!– Kamil Maciorowski
Jan 22 at 20:26
Now this is the answer! I was going to publish a solution based on
declare -p
. I thought it was decent, I still do; but yours is so much better there's no point in publishing my inferior one. My test array is like edg_cdi=('normal' 'with space' 'double"quote' "single'quote" $'new-n-line' 'backslash')
, your code handles it flawlessly. Good job!– Kamil Maciorowski
Jan 22 at 20:26
Additional reading on the topic with further examples and explanation for those that need even additional clarity perhaps..... Indirect References and Indirect variable references - the new way
– Pimp Juice IT
Jan 26 at 16:53
Additional reading on the topic with further examples and explanation for those that need even additional clarity perhaps..... Indirect References and Indirect variable references - the new way
– Pimp Juice IT
Jan 26 at 16:53
add a comment |
Your code should look like this
chosen='cdi'
edg_cdi="40 46 37 43"
edg_cdt="69 24 177 25"
string='edg_'
wholename=$string$chosen
for i in ${!wholename}
do
echo $i
done
As explained here
@Uxio Here's another related post that gives more detail about Variable Indirection: stackoverflow.com/questions/8515411/… too.
– Pimp Juice IT
Jan 22 at 18:52
@user1330614 Thank you for your reply, but, I think it is not working properly: The output of this answer is a single row: '40 46 37 43', a single echo. I need $i to be 40, then 46, then 37 and then 43. In this solution, edg_cdi is treated as a single string, but its required to be a set (array) of four independent elements, where the for loop can process independently.
– Uxio
Jan 22 at 19:09
I've tested the code myself and it outputs 40 46 37 and 43 in separated rows.
– user1330614
Jan 22 at 19:15
Make sure you don't enclose ${!wholename} between ""
– user1330614
Jan 22 at 19:18
@user1330614 Oh, sorry! True! Regards, thank you for your help.
– Uxio
Jan 22 at 19:20
|
show 2 more comments
Your code should look like this
chosen='cdi'
edg_cdi="40 46 37 43"
edg_cdt="69 24 177 25"
string='edg_'
wholename=$string$chosen
for i in ${!wholename}
do
echo $i
done
As explained here
@Uxio Here's another related post that gives more detail about Variable Indirection: stackoverflow.com/questions/8515411/… too.
– Pimp Juice IT
Jan 22 at 18:52
@user1330614 Thank you for your reply, but, I think it is not working properly: The output of this answer is a single row: '40 46 37 43', a single echo. I need $i to be 40, then 46, then 37 and then 43. In this solution, edg_cdi is treated as a single string, but its required to be a set (array) of four independent elements, where the for loop can process independently.
– Uxio
Jan 22 at 19:09
I've tested the code myself and it outputs 40 46 37 and 43 in separated rows.
– user1330614
Jan 22 at 19:15
Make sure you don't enclose ${!wholename} between ""
– user1330614
Jan 22 at 19:18
@user1330614 Oh, sorry! True! Regards, thank you for your help.
– Uxio
Jan 22 at 19:20
|
show 2 more comments
Your code should look like this
chosen='cdi'
edg_cdi="40 46 37 43"
edg_cdt="69 24 177 25"
string='edg_'
wholename=$string$chosen
for i in ${!wholename}
do
echo $i
done
As explained here
Your code should look like this
chosen='cdi'
edg_cdi="40 46 37 43"
edg_cdt="69 24 177 25"
string='edg_'
wholename=$string$chosen
for i in ${!wholename}
do
echo $i
done
As explained here
answered Jan 22 at 18:37
user1330614user1330614
1334
1334
@Uxio Here's another related post that gives more detail about Variable Indirection: stackoverflow.com/questions/8515411/… too.
– Pimp Juice IT
Jan 22 at 18:52
@user1330614 Thank you for your reply, but, I think it is not working properly: The output of this answer is a single row: '40 46 37 43', a single echo. I need $i to be 40, then 46, then 37 and then 43. In this solution, edg_cdi is treated as a single string, but its required to be a set (array) of four independent elements, where the for loop can process independently.
– Uxio
Jan 22 at 19:09
I've tested the code myself and it outputs 40 46 37 and 43 in separated rows.
– user1330614
Jan 22 at 19:15
Make sure you don't enclose ${!wholename} between ""
– user1330614
Jan 22 at 19:18
@user1330614 Oh, sorry! True! Regards, thank you for your help.
– Uxio
Jan 22 at 19:20
|
show 2 more comments
@Uxio Here's another related post that gives more detail about Variable Indirection: stackoverflow.com/questions/8515411/… too.
– Pimp Juice IT
Jan 22 at 18:52
@user1330614 Thank you for your reply, but, I think it is not working properly: The output of this answer is a single row: '40 46 37 43', a single echo. I need $i to be 40, then 46, then 37 and then 43. In this solution, edg_cdi is treated as a single string, but its required to be a set (array) of four independent elements, where the for loop can process independently.
– Uxio
Jan 22 at 19:09
I've tested the code myself and it outputs 40 46 37 and 43 in separated rows.
– user1330614
Jan 22 at 19:15
Make sure you don't enclose ${!wholename} between ""
– user1330614
Jan 22 at 19:18
@user1330614 Oh, sorry! True! Regards, thank you for your help.
– Uxio
Jan 22 at 19:20
@Uxio Here's another related post that gives more detail about Variable Indirection: stackoverflow.com/questions/8515411/… too.
– Pimp Juice IT
Jan 22 at 18:52
@Uxio Here's another related post that gives more detail about Variable Indirection: stackoverflow.com/questions/8515411/… too.
– Pimp Juice IT
Jan 22 at 18:52
@user1330614 Thank you for your reply, but, I think it is not working properly: The output of this answer is a single row: '40 46 37 43', a single echo. I need $i to be 40, then 46, then 37 and then 43. In this solution, edg_cdi is treated as a single string, but its required to be a set (array) of four independent elements, where the for loop can process independently.
– Uxio
Jan 22 at 19:09
@user1330614 Thank you for your reply, but, I think it is not working properly: The output of this answer is a single row: '40 46 37 43', a single echo. I need $i to be 40, then 46, then 37 and then 43. In this solution, edg_cdi is treated as a single string, but its required to be a set (array) of four independent elements, where the for loop can process independently.
– Uxio
Jan 22 at 19:09
I've tested the code myself and it outputs 40 46 37 and 43 in separated rows.
– user1330614
Jan 22 at 19:15
I've tested the code myself and it outputs 40 46 37 and 43 in separated rows.
– user1330614
Jan 22 at 19:15
Make sure you don't enclose ${!wholename} between ""
– user1330614
Jan 22 at 19:18
Make sure you don't enclose ${!wholename} between ""
– user1330614
Jan 22 at 19:18
@user1330614 Oh, sorry! True! Regards, thank you for your help.
– Uxio
Jan 22 at 19:20
@user1330614 Oh, sorry! True! Regards, thank you for your help.
– Uxio
Jan 22 at 19:20
|
show 2 more comments
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1397027%2fbash-for-loop-with-unknown-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
when you say the "selected array would be different" you mean an array with different data or a different type, like a simple variable? Anyway for the code you provide for cycle substitute "WHAT_TO_WRITE_HERE" with ${wholename[@]}
– AtomiX84
Jan 22 at 14:20
@Pimp Juice IT. The issue is I don't know the variable name. After knowing chosen='cdi', I can get wholename='edg_cdi'. But "${wholename[@]}" won't work.
– Uxio
Jan 22 at 15:56
@AtomiX84 The output of for i in "${wholename[@]}" is wrong: It's edg_cdi, when it shoud be 40 46 37 43.
– Uxio
Jan 22 at 15:57
This question is maybe a duplicated of stackoverflow.com/questions/10820343/…. Anyway I have fixed your code using the accepted answer there and it works.
– user1330614
Jan 22 at 18:39