Array Test: Looping through an array

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Why isn't this simple test returning any values for array index [1] and onwards?



#!/bin/bash

SessionName=(
'SessionName_1'
'SessionName_2'
)

srcds_run=(
'/path/to/srcds_run'
'/path/to/srcds_run_2'
)

array=(
SessionName
srcds_run
)

clear
echo

for element in "$array[@]"
do
echo "$element[0] = $!element[0]"
echo "$element[1] = $!element[1]"
done

echo
echo "literal printout test:"
echo "SessionName[0] = $SessionName[0]"
echo "SessionName[1] = $SessionName[1]"


The script outputs this:



SessionName[0] = SessionName_1
SessionName[1] =
srcds_run[0] = /path/to/srcds_run
srcds_run[1] =

literal printout test:
SessionName[0] = SessionName_1
SessionName[1] = SessionName_2


Thanks









share









New contributor




johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Possible duplicate of How to access further members of an array when using bash variable indirection?
    – don_crissti
    3 mins ago














up vote
1
down vote

favorite












Why isn't this simple test returning any values for array index [1] and onwards?



#!/bin/bash

SessionName=(
'SessionName_1'
'SessionName_2'
)

srcds_run=(
'/path/to/srcds_run'
'/path/to/srcds_run_2'
)

array=(
SessionName
srcds_run
)

clear
echo

for element in "$array[@]"
do
echo "$element[0] = $!element[0]"
echo "$element[1] = $!element[1]"
done

echo
echo "literal printout test:"
echo "SessionName[0] = $SessionName[0]"
echo "SessionName[1] = $SessionName[1]"


The script outputs this:



SessionName[0] = SessionName_1
SessionName[1] =
srcds_run[0] = /path/to/srcds_run
srcds_run[1] =

literal printout test:
SessionName[0] = SessionName_1
SessionName[1] = SessionName_2


Thanks









share









New contributor




johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Possible duplicate of How to access further members of an array when using bash variable indirection?
    – don_crissti
    3 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Why isn't this simple test returning any values for array index [1] and onwards?



#!/bin/bash

SessionName=(
'SessionName_1'
'SessionName_2'
)

srcds_run=(
'/path/to/srcds_run'
'/path/to/srcds_run_2'
)

array=(
SessionName
srcds_run
)

clear
echo

for element in "$array[@]"
do
echo "$element[0] = $!element[0]"
echo "$element[1] = $!element[1]"
done

echo
echo "literal printout test:"
echo "SessionName[0] = $SessionName[0]"
echo "SessionName[1] = $SessionName[1]"


The script outputs this:



SessionName[0] = SessionName_1
SessionName[1] =
srcds_run[0] = /path/to/srcds_run
srcds_run[1] =

literal printout test:
SessionName[0] = SessionName_1
SessionName[1] = SessionName_2


Thanks









share









New contributor




johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Why isn't this simple test returning any values for array index [1] and onwards?



#!/bin/bash

SessionName=(
'SessionName_1'
'SessionName_2'
)

srcds_run=(
'/path/to/srcds_run'
'/path/to/srcds_run_2'
)

array=(
SessionName
srcds_run
)

clear
echo

for element in "$array[@]"
do
echo "$element[0] = $!element[0]"
echo "$element[1] = $!element[1]"
done

echo
echo "literal printout test:"
echo "SessionName[0] = $SessionName[0]"
echo "SessionName[1] = $SessionName[1]"


The script outputs this:



SessionName[0] = SessionName_1
SessionName[1] =
srcds_run[0] = /path/to/srcds_run
srcds_run[1] =

literal printout test:
SessionName[0] = SessionName_1
SessionName[1] = SessionName_2


Thanks







bash array





share









New contributor




johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share









New contributor




johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share



share








edited 3 mins ago









don_crissti

47.9k15126155




47.9k15126155






New contributor




johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 6 mins ago









johndoe

111




111




New contributor




johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






johndoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Possible duplicate of How to access further members of an array when using bash variable indirection?
    – don_crissti
    3 mins ago
















  • Possible duplicate of How to access further members of an array when using bash variable indirection?
    – don_crissti
    3 mins ago















Possible duplicate of How to access further members of an array when using bash variable indirection?
– don_crissti
3 mins ago




Possible duplicate of How to access further members of an array when using bash variable indirection?
– don_crissti
3 mins ago















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






johndoe is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475637%2farray-test-looping-through-an-array%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








johndoe is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















johndoe is a new contributor. Be nice, and check out our Code of Conduct.












johndoe is a new contributor. Be nice, and check out our Code of Conduct.











johndoe is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475637%2farray-test-looping-through-an-array%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)