Can you tell me how to write a UNIX korn shell script program? I'm new to UNIX scripting and HP-UX UNIX operating system.
Korn shell scripting under UNIX / Linux can be used to automate lots of stuff. It easy to write a shell script. You must know how to use a text editor such as vi to write a script.
Writing your first Korn shell script
Let us write a shell program to print knowledge is power on screen. Type the following command to open file:
vi hello.ksh
The first line should be as follows:
#!/bin/kshIt is called a shebang. It consists of a number sign and an exclamation point character (#!), followed by the full path to the interpreter such as /bin/ksh. All scripts under UNIX execute using the interpreter specified on a first line.
Next append code as follows:
# A shell script to print message # Written by Tom - Jan/13/2008 print "Knowledge is power"
Save and close the file. At the end your script should look like as follows:
#!/bin/ksh # A shell script to print message # Written by Tom - Jan/13/2008 # ------------------------------ print "Knowledge is power"
Set executable permission
Type the following command to set executable permission:
chmod +x hello.ksh
Run your korn shell script
Type the following command:
./hello.ksh
Sample output:
Knowledge is power
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 6 comments… read them below or add one }
great job on youe xplainations. I enjoy your site
Its a good intro and i had successfully wrote my first script, but its better to have a vi or any other editor tutorial mix with this, i first learn the vi and then this one, and it works.
Anyways a goood one. Thanks once again.
hi,
please give me some programs which r follows.
1)write a shell script program take two strings & check that the string are same or not
2) sript program to take marks of five subject of a students with name & display the grade in which he is passed .
3) enter a character from a user & check that itbis a lower case letter, upper case letter, digit, special char.
4)write a program to find the string is start with ovel, digita, or ends with digit, ovel & the word contains of five letters.
5)create a file student.dat which contain details of student as rool no.,name,want to be, on plattform, birthdate.
I am new to this program and I do not know where to begain. This is my directions and yes I am s student trying to learn this. and no I am not looking for you to do it for me just help me along.
Write a Unix shell script (one program) called Project1_lastname (your lastname). This script will do the following tasks:
Using “if” statement checks for a file called “student.txt” in the current directory. Removes (deletes) the file if it exist. This file will collect last name, first name, and grade for 5 students.
Use a while loop to get the information (last name, first name, and grade) for 5 students. Grades should be 0-100. Use three different variable names (fname, lname, and grade) to read the data from the keyboard.
Store the data read from the keyboard in a file called “student.txt”. After reading all the data for 5 students, display contents of student.txt file on the monitor.
i want something more apart from this.