How do I get a range-list parameter like “1-6,8,15-20,23,25-28,30” to be parsed/expanded (to “1 2 3 4 5 6 8 15 16 17 18 19 20 23 25 26 27 28 30”) with bash? If bash does not work, some other generally available Linux shell coud be considered.
Use case: I have a script that needs to do something with given IDs, and would be (more than) nice to be able to handle “all kinds of” ID lists/ranges in one go. Now my script takes only a single ID range parameter A-B, so if my ID list is not a single contunuous range I need to run the script several times with different range parameters (e.g. “A-B,X-Y” becomes two runs, first “A-B” and then “X-Y”).
Short spec for the list parameter:
– a list is one range, or several ranges separated by a comma (other separators also possible)
– a range is A-B (A smaller than B), or a single number X (special case A=B)
– this is numerical/integer ranges/lists, so the possible characters in list are 0-9, “-” and “,”
Here’s a
bashfunction that uses parameter expansion, thereadcommand, and theseqcommand to parse and expand a string in the format you gave.