Skip to content

Instantly share code, notes, and snippets.

@partap
Last active December 11, 2015 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save partap/4677744 to your computer and use it in GitHub Desktop.
Save partap/4677744 to your computer and use it in GitHub Desktop.
bash: parse number range from command line
#!/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