Array Test: Looping through an array

Clash 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
bash array
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.
add a comment |Â
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
bash array
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
add a comment |Â
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
bash array
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
bash array
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.
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
add a comment |Â
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
add a comment |Â
active
oldest
votes
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
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
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
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
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
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
Possible duplicate of How to access further members of an array when using bash variable indirection?
â don_crissti
3 mins ago