There is a space in between
$ echo {0..9}
0 1 2 3 4 5 6 7 8 9
How do I produce similar output using echo {0..9} without space?
Desired output
0123456789
try:
echo -e \\b{0..9}
from man echo:
-e enable interpretation of backslash escapes
\b backspace
or better to use printf:
printf '%s' {0..9}
or to add last newline:
printf '%s' {0..9} $'\n'
Use tr to remove the spaces:
$ echo {0..9} | tr -d ' '
tr man page:
-d, --delete
delete characters in SET1, do not translate
For the record, note that {0..9} does come from zsh initially.
Like csh's {a,b} which it builds upon, it expands to separate arguments.
So for those to be bundled back together on output, you need a command that prints or can print its arguments joined with each other, like printf:
printf %s {0..9}
(though that doesn't print the terminating newline, see αғsнιη's answer to work around it)
Or have an extra step that does the joining.
In zsh, you can join elements of an array with nothing in between with ${(j[])array}, so you could use an anonymous function like:
() { print ${(j[])@}; } {0..9}
or
function { print ${(j[])@}; } {0..9}
In Korn-like shells (including bash and zsh), to join elements of any array with nothing, you use "${array[*]}" whilst $IFS is empty:
set {0..9}
IFS=
echo "$*"
(here using echo instead of print, as though bash is a Korn-like shell even more so than zsh, it didn't implement the print builtin).
With bash or zsh, you can also do the joining into a variable with:
printf -v var %s {0..9}
echo $'\e[D'{0..9}
0123456789
In the terminal it looks solid but is actually connected by the separator out of the terminal control sequences.
echo $'\e[D'{0..9} | cat -vet
^[[D0 ^[[D1 ^[[D2 ^[[D3 ^[[D4 ^[[D5 ^[[D6 ^[[D7 ^[[D8 ^[[D9$
'\e[D' - move cursor left
echo $'string' or echo -e 'string' - enable interpretation of backslash escapes.
echo 0123456789– Oct 08 '20 at 06:170-9is just an example, what if you've up to1000? Still want to do it manually? – Wolf Oct 08 '20 at 06:19012...9989991000) be good for? – Oct 08 '20 at 06:30