How To Write First UNIX Korn Shell Script Program

How To Write First UNIX Korn Shell Script Program

To write your first Unix Korn shell script program, you will need to follow these steps:

  1. Create a new file using a text editor. Open a text editor, such as vi or nano, and create a new file. This file will contain the Korn shell script.

  2. Add the #! shebang line at the top of the file. The shebang line specifies the interpreter that should be used to execute the script. For a Korn shell script, you should use #!/bin/ksh.

  3. Write the commands for the script. In the script, you can include any commands that you would normally enter at the command prompt. These commands will be executed in the order they are written.

  4. Save the file and make it executable. Save the file with a .ksh extension, and make it executable using the chmod command:

chmod +x script.ksh
Sou‮.www:ecr‬lautturi.com
  1. Run the script. To run the script, enter the name of the script file at the command prompt:
./script.ksh

Here is an example of a simple Korn shell script that displays the message "Hello, World!" and the current date:

#!/bin/ksh

echo "Hello, World!"
date
Created Time:2017-10-29 22:08:34  Author:lautturi