---
title: "How to Write a Script in K Shell"
description: "Scripting is very powerful in Linux operating systems and it is so common. I have given my first script that I have practised during my learning so that you can learn Script how to write and execute it quickly."
url: https://srinimf.com/2017/11/01/ksh-script-steps-to-create-awesome-way/
date: 2017-11-01
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2017/11/how-to-write-script.jpg?fit=1200%2C700&ssl=1
categories: ["UNIX"]
tags: ["How to run shell script", "Learn shell scripting", "UNIX tips and Tricks"]
type: post
lang: en
---

# How to Write a Script in K Shell

**In the UNIX/Linux environment**, there are many shell programs available. To run a Script in Unix you need shell programming to be installed in your Linux/Unix Os. Why I chose this topic is we are in the automation age and the automated things that run in the form of [Script](https://www.webopedia.com/TERM/S/script.html).

Related[How to write Menu Driven CICS programs](https://srinimf.com/2016/04/06/cics-menu-driven-programs/)

---

**The list of different shell programs**

1. Bourne Shell
2. Bourne again shell (Bash)
3. C Shell
4. T Shell
5. K shell

I have recently installed CentOs in my Vmware player and created Virtual machine. I installed light version of CentOs. In that, by default, only bourn shell available.

I want [to install](https://srinimf.com/2018/03/17/centos-python-pandas/) ‘Korn Shell’, so installed KSH using the below command. [You can](https://srinimf.com/2021/01/19/python3-how-to-install-beautifulsoup-parser/) learn Linux scripting quickly without missing a single point here.

Related[How to Write Echo Command Correctly in Linux](https://srinimf.com/2022/12/03/how-to-write-echo-command-correctly-in-linux/)

```
$ yum install  ksh
```

The below script I have created as a part of my learning.

$ vi myfirstscript.sh

Then, it goes to edit mode…Always better write your code only in small case letters. Since some interpreters, does not support Capital case letters.

The first symbol ‘#!’ indicates the location of your ‘**ksh’** program. After entering into edit mode you need to press ‘Ins’, else, it will not allow you to edit.

The ‘;;’ indicates that end statement for each case.

The ‘*’ indicates that when other condition.

```
#My first menu script
#!/bin/ksh
echo " Enter Your Option Here:"

select menu_selections in Y N Q
do
  case $menu_selections in 
  Y) echo "Happy Birthday "
     ;;
  N) echo "Not Your Birthday "
     ;;
  Q) echo "Later tater "
     ;;
  *) echo "Invalid user"
     ;;
  esac
done
#End of script.
```

After entering the above pres ‘Esc’ and at the end give ‘:wq”. This means that quit and save.

$ ./myfirstscript.sh

Initially you will get an error, because you do not have execution permission. So, first you need to give permission. [See more on file permissions.](http://www.filepermissions.com/file-permission/775)

$chmod 775 myfirstscript.sh

Then

$./myfirstscript.sh

The display comes as…

```
Enter Your Option Here:

1)Y
2)N
3)Q
#?
```

So, just give 1, 2, or 3 and any other number and verify the result. This is the first script I practiced. So I am sharing it with you.

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2017%2F11%2F01%2Fksh-script-steps-to-create-awesome-way%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2017%2F11%2Fhow-to-write-script.jpg%3Ffit%3D1200%252C700%26ssl%3D1&description=How%20to%20Write%20a%20Script%20in%20K%20Shell)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2017/11/01/ksh-script-steps-to-create-awesome-way/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2017/11/01/ksh-script-steps-to-create-awesome-way/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2017/11/01/ksh-script-steps-to-create-awesome-way/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2017/11/01/ksh-script-steps-to-create-awesome-way/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Write%20a%20Script%20in%20K%20Shell&body=https%3A%2F%2Fsrinimf.com%2F2017%2F11%2F01%2Fksh-script-steps-to-create-awesome-way%2F&share=email)
-

### Like this:

Like Loading…
