In case you feel adventurous and want to use zsh
instead of bash
, you can use the following:
- For zsh versions below 5.0.7 you can use the
BRACE_CCL
option:
(snip man zshall) If a brace expression matches none of the above forms, it is left
unchanged, unless the option BRACE_CCL
(an abbreviation for 'brace character class') is set. In that case, it is expanded to a list of the individual characters between the braces sorted into the order of the characters in the ASCII character set (multibyte characters are not currently handled). The syntax is similar to a [...]
expression in filename generation: -
is treated specially to denote a range of characters, but ^
or !
as the first character is treated normally. For example, {abcdef0-9}
expands to 16 words 0 1 2 3 4 5 6 7 8 9 a b c d e f
.
#!/usr/bin/env zsh
setopt brace_ccl
echo "give start letter"
read cstart
echo "give stop letter"
read cstop
for char in {${cstart}-${cstop}}; do echo $char; done
- For zsh versions from 5.0.7 onwards you can use the default brace expansion :
An expression of the form {c1..c2}
, where c1
and c2
are single characters (which may be multibyte characters), is expanded to every character in the range from c1
to c2
in whatever character sequence is used internally. For characters with code points below 128 this is US ASCII (this is the only case most users will need). If any intervening character is not printable, appropriate quotation is used to render it printable. If the character sequence is reversed, the output is in reverse order, e.g. {d..a}
is substituted as d c b a
.
#!/usr/bin/env zsh
echo "give start letter"
read cstart
echo "give stop letter"
read cstop
for char in {${cstart}..${cend}; do echo $char; done
More information on zsh
can be found here and the quick reference