Executing Korn Shell Scripts

Let's make a Korn shell script out of the print Hello world command by putting it into a file like this:

					$ print "print Hello world" >prhello
				

Before Korn shell scripts can be executed, they must be made executable by setting the execute and read bits with the chmod command:

					$ chmod 755 prhello
				

or

					$ chmod +rx prhello
				

Assuming that the current directory is in the search path $PATH, prhello can now be executed by simply invoking it by name:

					$ prhello
					Hello world
				

Korn shell scripts can also be executed by invoking them as the first argument to ksh:

					$ ksh prhello
					Hello world
				

Now we can use prhello like any other command. The output can be directed to a file:

					$ prhello >p.out
					$ cat p.out
					Hello world
				

It can ...

Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.