What are Shell Scripts?

Posted:  May 14th, 2018

 

Shell scripts are executable files, that contain one or more SSH commands grouped together.

These commands will be run one-by-one, when you execute the script file from the shell.

 

A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script which sets up the environment, runs the program, and does any necessary cleanup, logging, etc. is called a wrapper.

 

The term is also used more generally to mean the automated mode of running an operating system shell; in specific operating systems they are called other things such as batch files (MSDos-Win95 stream, OS/2), command procedures (VMS), and shell scripts (Windows NT stream and third-party derivatives like 4NT—article is at cmd.exe), and mainframe operating systems are associated with a number of terms.

 

A shell script can provide a convenient variation of a system command where special environment settings, command options, or post-processing apply automatically, but in a way that allows the new script to still act as a fully normal Unix command.

 

Follow the steps mentioned below to execute a shell script:

 

1) Login with SSH as root.

 

2)  Navigate to the directory where the script is residing using the cd command.

 

    cd /path/to/file/

 

3) Your script file must have executable permissions, if not, change the permissions to 755.

(For example, your shell script file is named script.sh)

 

    chmod 755 script.sh

 

4) To execute the script, just type the following command from the same directory where the script file exist:

.

    /script.sh