The AIX operating system and other UNIX-like operating systems need a way to communicate with the kernel. This is done through the use of a shell. The Korn shell is the default shell used with AIX. Discover how to automate many tasks and save a great deal of time by writing your own Korn shells scripts.
It should read as The user of the Operating System, not the OS itself. The OS itself, it’s programs, communicate through POSIX API calls, not through the shell. The shell is meant to be used by the user.
Edited 2008-06-26 18:15 UTC
Also OpenBSD uses the Korn shell as default shell (actually the Public Domain Korn Shell).
On Sun Solaris, the Korn shell is mostly used as the interactive shell, while scripts (system scripts) rely on the UNIX’s standard shell, the Bourne shell. The ksh’s syntax compatibility to sh makes it appealing to its users.
I can’t remember what the default dialog shell was on IRIX, I think it was the C shell. FreeBSD uses csh by default. Both of these UNIXes use sh for system scripting.
The mentioned examples would mostly run with the Bourne Shell (sh) and the Bourne Again Shell (bash), too. One important difference is the use of [[…]] for testing expressions; here, (ba)sh uses […].
ksh and (ba)sh use the same kind of variable association; evaluation from a program call done with $(…) is compatible; (ba)sh allows you to use `…`, too. The basic contructs demonstrated (“if”, “for”-“do”, “case”) are compatible to (ba)sh.
A difference you see at the tirst look is the use of “print” (ksh internal) instead of “echo”.
One thing about consistent form: The article features conditionals in this form:
if [[ $? = 0 ]]; then
________print “The date command was successful”
else
________print “The date command failed
fi
but illustrates iterations in this way:
for username in $(cat $PASSWORD_FILE | cut -f1 -d:)
do
________print $username
done
Here, you can use this form, too:
for username in $(cat $PASSWORD_FILE | cut -f1 -d:); do
________print $username
done
You can substitute the line break between the “for” statement and “do” with a “;” which makes shell scripts tidy, in my opinion. If you use tabs to indent functional groups and find an ending sign, such as “fi”, “done” or “esac”, you just need to go up in the same column and the first thing you’ll find is the expression causing this ending sign (except “else” in “if” conditionals). If you don’t like the “;”, use the line break (and proper indentation) method everywhere.
A more tidy approach to the if_error function is welcome.
function if_error {
________if [[ $? -ne 0 ]]; thenfunction
________________print “$1”
________________exit $?
________fi
}
Statements of the same “level” should start in the same column. Tidy scripting code is very important especially if you want to give your work to others for education and further use.
Sorry I had to use underscores. HTML does eat up the spaces, and there’s no <pre> available here.
If you’re familiar with (ba)sh, reading and creating ksh scripts (at this level of complexity) won’t be problematic for you. Nice article!
Notable post …
Thanks for sharing !
Don’t you a have a webpage in which you publish all this stuff?
I’ve been following your posts … and if you do have a page or a blog, I would very much like to bookmark it
Blessings