• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

How to write Shell Script in Linux/Unix

AnonyViet by AnonyViet
December 6, 2025
in Tips
0

Shell Scripting is an open source computer program designed to be run by Unix/Linux shell. shell. Shell Scripting is a program that writes a series of commands for the shell to execute. It can combine long and repetitive command sequences into a single and simple script that can be stored and executed at any time.

Join the channel Telegram belong to AnonyViet 👉 Link 👈

In this article, you will learn the basics of Linux/Unix shell scripting programs to advanced concepts of Shell Scripting. The article is designed for beginners and experts who want to learn what is Shell Scripting? How shell scripting works, types of shells and more.

What is Shell?

Shell is a UNIX term that refers to the interface between the user and the operating system service. The shell provides the user with an interface and accepts commands that the user puts into the system and executes those commands automatically, providing the results of the program in a shell script.

An operating system is made up of many components, but its two main components are:

shell script

Kernel is the nucleus of the computer. It helps the system communicate between hardware and software. While the Kernel is the innermost part of the operating system, the shell is the outermost part.

The shell in the Linux operating system receives input from the client in the form of a command, processes it, and then outputs the results. It is the interface through which users can work on programs, commands, and scripts. The shell is accessed using the terminal.

When you run the terminal, the shell issues a command prompt (usually $)where you can enter a command, which will then be executed when you press the Enter key. The output or result will then be displayed on the terminal.

The Shell wraps around the delicate insides of the Operating System, protecting it from accidental damage. Therefore it is called Shell.

Types of shells

There are two main types of shells in Linux:

  1. Bourne Shell: The prompt for this shell is $ and subshells include:
    • POSIX shell is also known as sh
    • Korn Shell is also called sh
    • Bourne Again Shell is also known as bash (most commonly)
  2. C shell: The prompt for this shell is % and different types like
    • C shell is also known as csh
    • Top C shell is also known as tcsh

We will discuss shell scripting based on bash shell in this article.

How to write Shell Script in Linux/Unix

Shell Scripts are written using text editors (text editors). On a Linux system, open an editors program, open a new file to start typing a shell script or shell programming, then give the shell permission to execute the shell script and place your script in a location where the shell can find it.

Steps to create Shell Script:

  1. Create file using vi editor (or any other text editor). The name of the script file must have the extension .sh
  2. Start the script with #! /bin/sh
  3. Write a few lines of code
  4. Save the script file as filename.sh
  5. Execute the script file using the command bash filename.sh

“#!” is an operator called a shebang that directs the script to the interpreter location. So if we use “#! /bin/sh”, the script will be redirected to bourne-shell.

Let’s create a small script:

#!/bin/sh
ls

Steps to create Shell Script program in Linux/Unix:

How to write Shell Script in Linux/Unix 7

The ‘ls’ command is executed when we execute the sample.sh script file.

Commenting is a very important element in any program. In Shell programming, the syntax for adding comments is, the content after the mark # will have no value, the purpose is to explain the author’s code.

#comment

For example:

How to write Shell Script in Linux/Unix 8

What are variables in Shell?

As discussed earlier, variables store data in the form of characters and numbers. Similarly, shell variables are used to store information and they work only in the shell.

For example, create a shell variable and then print it out:

variable ="Hello"
echo $variable

Below is a small script that will use the variable:

#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"

Steps to create and execute script:

How to write Shell Script in Linux/Unix 9

As you can see, the program has chosen the value of the variable ‘name’ as “Joy” and ‘remark’ as “excellent”.

This is a simple script. You can develop advanced scripts containing conditional statements, loops, and functions. Shell Script will make your life and Linux administration easier.

Frequently asked questions

What is a shell script and why should I use it?

Shell script is a set of Unix/Linux commands written in a text file. It allows you to automate repetitive tasks, combine multiple commands into one, and increase system administration efficiency.

What tools do I need to write shell scripts?

You only need a text editor (like vi, nano, gedit) to write the script and a terminal to execute it. The Linux/Unix operating system has built-in necessary tools.

How to run a shell script?

After saving the script with the .sh extension, you need to grant execution permission with the command chmod +x your_script.sh and then run it using command ./your_script.sh.

Previous Post

How to completely uninstall WSL on Windows 11?

Next Post

Free Gemini Google certification exam guide and Answers

AnonyViet

AnonyViet

Related Posts

Instructions on how to make money from personal Facebook
Tips

Instructions on how to make money from personal Facebook

May 2, 2026
How to add sliders to Facebook Stories to easily rewind videos
Tips

How to add sliders to Facebook Stories to easily rewind videos

April 21, 2026
How to change the default font on Windows 10
Tips

How to change the default font on Windows 10

April 13, 2026
5 tips for using a Browser to replace an App (helps save RAM, time and money)
Tips

5 tips for using a Browser to replace an App (helps save RAM, time and money)

April 13, 2026
How to make funny MeMe photos without Photoshop within 10 seconds
Tips

How to make funny MeMe photos without Photoshop within 10 seconds

April 11, 2026
How to quickly design your own Logo without Photoshop
Tips

How to quickly design your own Logo without Photoshop

April 10, 2026
Next Post
Free Gemini Google certification exam guide and Answers

Free Gemini Google certification exam guide and Answers

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Cat Gatekeeper: Cat gatekeeper utility, uniquely helps to “quit” social networks

Cat Gatekeeper: Cat gatekeeper utility, uniquely helps to “quit” social networks

May 7, 2026
How to block pop-up ads on Safari without installing an app

How to block pop-up ads on Safari without installing an app

May 6, 2026
Instructions on how to upgrade CapCut Pro for free using Filza

Instructions on how to upgrade CapCut Pro for free using Filza

May 5, 2026
TikTok Pro Tools: “all in one” utility for Top Top addicts

TikTok Pro Tools: “all in one” utility for Top Top addicts

May 4, 2026
Cat Gatekeeper: Cat gatekeeper utility, uniquely helps to “quit” social networks

Cat Gatekeeper: Cat gatekeeper utility, uniquely helps to “quit” social networks

May 7, 2026
How to block pop-up ads on Safari without installing an app

How to block pop-up ads on Safari without installing an app

May 6, 2026
Instructions on how to upgrade CapCut Pro for free using Filza

Instructions on how to upgrade CapCut Pro for free using Filza

May 5, 2026
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Cat Gatekeeper: Cat gatekeeper utility, uniquely helps to “quit” social networks

Cat Gatekeeper: Cat gatekeeper utility, uniquely helps to “quit” social networks

May 7, 2026
How to block pop-up ads on Safari without installing an app

How to block pop-up ads on Safari without installing an app

May 6, 2026
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply