I use seq a lot in my simulation shell scripts. The Git bash does not provide it, thus I am looking for an alternative.
Is there an alternative to seq
that is part of the commands supported by the Git bash?
Current Solution: Based on Ignacio's answer I wrote a little helper script that provides my legacy scripts with a simple seq
function. I also noticed, when using echo {1..10}
with variables, you need to use eval
to get the sequence output instead of the unexpanded expression:
a=0; b=5
eval echo {$a..$b} # outputs 0 1 2 4 5
echo {$a..$b} # outputs {0..5}
Here is my new seq.sh
:
#!/bin/bash
# check for the real seq and export a new seq if not found
# import this script via `source ./seq.sh`
#
hasSeq(){
which seq >/devnull 2>&1
}
mySeq(){
case $# in
1) eval echo {1..$1};;
2) eval echo {$1..$2};;
3) echo "seq(3) not supported" 1>&2;;
esac
}
if ! hasSeq; then
seq(){
mySeq $*
}
fi
hasSeq || export -f seq
Assuming the version of bash is recent enough, you could use brace expansion.
$ echo {1..16}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Or... you know...