Is there a way to implement the following using 'for' in KornShell (ksh)? Here is the C equivalent:
for(i=1;i<20;i++)
{
printf("%d",i);
}
I was wondering if this can be implemented using just 'for' and not 'while'
I tried the following, it does not seem to work.
for i in [1-20]
do
print $i
done
Please let me know your ideas and solutions.
ksh93 offers braceexpansion also if "braceexpand" is "on". Check with "set -o" and then use curly braces {}
Not really an answer, but an FYI to casual ksh users.
Edit 2019-05-12 (Minor edits below in bold, other info is now
stricken).To clarify on several comments here, there are 2 ksh's available in typical vendor installations (non-Linux (maybe them too?)).
Solaris and AIX have a ksh and ksh93 (probably true for other vendors too). The base ksh is also known as ksh88. Ksh93 is described in The New Kornshell Command and Programming Language, 1995
Linux systems that have a true ksh (not pdksh), mostly use ksh93 named as ksh.
Finally, to further confuse things, don't let the 1995 pub date trick you, ksh
continues underwas under active development by David Korn and Glen Fowler at AT&T until 2012?. Versions were released 2-3X per year. Some Linux versions pick up the newer versions.These newer versions have very advanced features (most of this taken from
AT&T research UWIN page. search for the link 'notes and changes'(dead link) )(note that ...s in above, usually indicate some qualifying information removed)
Korn and Fowler had also produced an advanced environment, UWIN (Unix for Windows) for people that use systems like Mingw or Cygwin, that would be worthy of a separate post. The downside for UWIN is,
AT&T Common Public License V 1.0Eclipse Public License* is not GNU.See
UWin main page(dead link) : unfortunately out of date, better to nose around in the dnld link above. Hmm, this is much betterGlenn Fowler's FAQ for UWin(also dead, Time Machine anyone?).I hope this helps!
Edit 2019-05-12 . The reason for the dead links? David Korn and Glen Fowler Laid Off (at AT&T, 2012?
Information later surfaced that they are working at Google. I can't confirm this, so consider it as an old rumor.
AND see Is Ksh93 dead?
There still seems to be some activity at the ast git-hub site .
ast
is the over-arching package that includesksh93
. You can get the fresh source code there and compile it.Here is the text of the project description. (There is considerably more information in the
README.md
).* The EPL replaced AT&T's original CPL.
ksh93 supports the C-like
(( ...;...; ...))
:This will produce:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Heck, even the old syntax (using '{' ... '}' instead of 'do ... done' will work):
In older shells, you can still get the same effect with
Unfortunately, it looks as if
ksh
does not have support for range-based brace expansion or support the(( ))
construct so to do this compactly, you'll need to call the external binaryseq
like so: