I would like to save a range in a variable to use it later in for loop.
I have the code:
handshake=("wink" "double blink" "close your eyes" "jump")
code=$1
result=()
if ((code >> 4)); then
for i in {3..0..-1}; do
((1 & (code >> i))) && result+=("${handshake[$i]}")
done
else
for i in {0..3}; do
((1 & (code >> i))) && result+=("${handshake[$i]}")
done
fi
I would like to re-write the construction like:
range=((code >> 4)) ? {3..0..-1} : {0..3}
for i in $range; do
((1 & (code >> i))) && result+=("${handshake[$i]}")
done
How to do this in bash?