Linux Shell Scripting (Writing and Executing a Shell script)



Linux Shell Scripting (Writing and Executing a Shell script)

Linux Shell Scripting (Writing and Executing a Shell script)

This tutorial shows how to write and execute a simple shell script. Steps —
1) Use any text editor to write the shell script

2) Save the file with .sh extension eg. first.sh .

3) Open terminal and go to the folder where you saved the file.

4) To execute the script, type:
chmod +x file_name
./file_name

5) To execute the script without setting the execute permission, type:
interpreter_name file_name e.g., bash first.sh

6) To execute the script inside the current shell***, type:
. file_name (alternatively, type: source file_name)

(*** The other two options launch a new shell and execute the commands in it. But sometimes we need to run the script in the present shell.)

Comments are closed.