Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Range-expansion/UNIX-Shell/range-expansion.sh
Normal file
19
Task/Range-expansion/UNIX-Shell/range-expansion.sh
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
range_expand () (
|
||||
IFS=,
|
||||
set -- $1
|
||||
n=$#
|
||||
for element; do
|
||||
if [[ $element =~ ^(-?[0-9]+)-(-?[0-9]+)$ ]]; then
|
||||
set -- "$@" $(eval echo "{${BASH_REMATCH[1]}..${BASH_REMATCH[2]}}")
|
||||
else
|
||||
set -- "$@" $element
|
||||
fi
|
||||
done
|
||||
shift $n
|
||||
echo "$@"
|
||||
# to return a comma-separated value: echo "${*// /,}"
|
||||
)
|
||||
|
||||
range_expand "-6,-3--1,3-5,7-11,14,15,17-20"
|
||||
Loading…
Add table
Add a link
Reference in a new issue