Skip to content

Instantly share code, notes, and snippets.

@d630
Last active June 30, 2016 21:20
Show Gist options
  • Save d630/89d91630aa294024c91ec06ec1c0331b to your computer and use it in GitHub Desktop.
Save d630/89d91630aa294024c91ec06ec1c0331b to your computer and use it in GitHub Desktop.
bash: Use all elements of all arrays in one for-clause; see https://forum.ubuntuusers.de/topic/verarbeitung-von-arrays/
TEST_A=(
'1a'
'2a'
'3a'
)
TEST_B=(
'1b'
'2b'
'3b'
)
# Nr. 1
source reg.txt
for a in "${!TEST@}"
do
# eval 'A=("${'"${_a}"'[@]}")'
typeset -a 'A=("${'"${a}"'[@]}")'
for aa in "${A[@]}"
do
echo "$aa"
done
done
# Nr. 2
source reg.txt
for a in "${!TEST@}"
do
A="$a[@]"
for aa in "${!A}"
do
echo "$aa"
done
done
@d630
Copy link
Author

d630 commented Jun 23, 2016

Nr. 3

(geirha in bash@freenode):

source reg.txt
typeset -a "A=( $(printf '"${%s[@]}" ' "${!TEST_@}") )"
for a in "${A[@]}"
do
        echo "$a"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment