Shell scripts are just a list of commands executed sequentially.
<aside> ✅ Example
The following script uses the read command which takes the input from the keyboard and assigns it as the value of the variable PERSON and finally prints it on STDOUT.
#!/bin/sh
echo "What is your name?"
read PERSON
echo "Hello, $PERSON"
Here is a sample run of the script −
$./test.sh
What is your name?
Zara Ali
Hello, Zara Ali
</aside>
In Unix, there are two major types of shells −
The Bourne Shell has the following subcategories −
Assume we create a test.sh script.
Note all the scripts would have the .sh extension.
You need to alert the system that a shell script is being started.
This is done using the shebang construct. For example −
#!/bin/sh
This tells the system that the commands that follow are to be executed by the Bourne shell.
It's called a shebang because the # symbol is called a hash, and the ! symbol is called a bang.
To create a script containing these commands, you put the shebang line first
#!/bin/bash
pwd
ls
Save the above content and make the script executable −
$chmod +x test.sh
The shell script is now ready to be executed −
$./test.sh