Last active
December 11, 2015 23:38
-
-
Save partap/4677744 to your computer and use it in GitHub Desktop.
bash: parse number range from command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
xmldebug=0 | |
USAGE="Usage: $0 plateid1 [plateid2 ...] | |
(plateids can also be a range xxx-yyy)" | |
if [ "$#" == "0" ]; then | |
echo "$USAGE" | |
exit 1 | |
fi | |
classifyplate () { | |
plateid=$1 | |
echo Classifying plateid: $plateid | |
} | |
while (( "$#" )); do | |
# Set In-File-Separator to '-', so xxx-yyy parses into an array | |
IFS='-' | |
range=($1) | |
unset IFS | |
shift | |
plateid=${range[0]} | |
end=${range[1]:-$plateid} | |
#echo start: $plateid, end: $end | |
while [ $plateid -le $end ] | |
do | |
classifyplate $plateid; | |
plateid=$[$plateid+1] | |
done | |
done | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment