logo
. . .

How to Write Scripting in Centos 7

What is Shell?

Shell is a UNIX term for an interface between a user and an operating system service. Shell provides users with an interface and accepts human-readable commands into the system and executes those commands which can run automatically and give the program’s output in a shell script.

Types of Shell

There are two main shells in Linux:

1. The Bourne Shell: The prompt for this shell is $ and its derivatives are listed below:

POSIX shell also is known as sh
Korn Shell also knew as sh
Bourne Again SHell also knew as bash (most popular)

2. The C shell: The prompt for this shell is %, and its subcategories are:

C shell also is known as csh
Tops C shell also is known as tcsh

To write scripting in CentOS 7, you can use any text editor available in CentOS 7 such as Vi, Vim, Nano, or Emacs. These editors are installed by default in CentOS 7. Here’s a step-by-step guide to creating and writing a simple shell script:

Step 1:- Open a terminal in CentOS 7.

Step 2:- Choose a text editor. For example, to use Nano, you can type.

# [nano myscript.sh]
Replace myscript.sh with the desired name for your script.

Step 3:- This will open the Nano text editor. Now, you can write your script. For example:

#! /bin/bash
# This is a simple script
# [echo “Hello, CentOS 7!”]

In this example, #!/bin/bash is called a shebang, which tells the system to execute the script using the Bash shell. The echo command is used to print “Hello, CentOS 7!” to the terminal.

Step 4:- Once you have finished writing your script, you can save it by pressing
‘Ctrl + O’ to write out the file, then press Enter. To exit Nano, press ‘Ctrl + X’.

Step 5:- Make the script executable by running the following command:

# [chmod +x myscript.sh]
This command gives execute permission to the script.

Step 6:- Finally, to run the script, type:
# [./myscript.sh]
Replace myscript.sh with the name of your script if it’s different.

Please feel free to reach out to us for top-quality hosting products, such as Web Hosting, cPanel Hosting, Cyberpanel Hosting, Cloud VPS, Dedicated Servers in India, Email Hosting, Backup Solutions, Windows Server, and Linux Server. We are here to assist you with all your hosting needs.