I have a question with range variables in for loops. In for loops I know you can use {..} to define a range. But I want it to be customer definable. So the script asks for a range value, and I want it to be flexible. like this:
#!/bin/bash
while true;
do
echo "Some explenation..."
read -p "Possible values are: ALL or RANGE (to define a specific range):" answer
case $answer in
#ALL
[aA][lL][lL] )
echo "ALL is selected, 1 to 250"
RANGE="{1..250}"
break
;;
#RANGE
[rR][aA][nN][gG][eE] )
echo "Range is selected, please define a custom range. Notation should be like: <start>..<stop>"
echo "or: <single> <single>"
echo "or a combination of both. Like: 1..23 28 29 101..145 180 212"
read RANGE
break
;;
#OTHERS
* )
echo "Typo error!! Not correct, type again ALL, PRI, SEC or
RANGE"
;;
esac
done
echo ""
echo "Range for this execution is set to:"
echo "$RANGE"
for NEXI in $RANGE
do
sleep 0.2
echo "Nexus number: $NEXI"
done
echo ...
But the Output when I enter {1..10} 52 54 {120..128} is:
Nexus number: {1..10}
Nexus number: 52
Nexus number: 54
Nexus number: {120..128}
while I expected it to be like:
Nexus number: 1
Nexus number: 2
Nexus number: 3
Nexus number: 4
Nexus number: 5
Nexus number: 6
Nexus number: 7
Nexus number: 8
Nexus number: 9
Nexus number: 10
Nexus number: 52
Nexus number: 54
Nexus number: 120
Nexus number: 121
... etc.
fully written out.
What can I change to achieve this?
Thanks.