Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Bash Scripting – How to Run Bash Scripting in Terminal

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we are going to see how to run bash script in terminal. For example, we create a bash file set of instructions or commands ( known as bash script ), and through command, we can run this file in terminal.

Let see how to run bash script in terminal.

Example 1 : 

In this example we print or echo some text on screen with the help of a terminal.

$ echo "Geeks For Geeks"

Output : 

Print the text using echo command

Note : ” echo” this command will display the text on screen.

Example 2 :

In this example, we print the date of command execution with the help of terminal.

$ date

Print date using date command in terminal

Example 3 :

In this example, we will see that how to run a bash script file through a terminal. First, create a bash file named ” ” by the following command.

$ touch

Here, you can see that the file name is ” “. Whenever you create a bash script file use “.sh ” extension.

Note : ” touch “ is used to create file.

Now to write bash script, we should open this file in text editor using terminal.

$ nano

Note :nano ” is used to open file in text editor ( i.e. GNU nano )

Now, the text editor is opened. Write the following bash script into ” “


echo "Enter Your Name : "

read name

echo "Hello $name ! Welcome to our Geeks for Geeks site." 

Note : Where,

  • #! : It is known as shebang.
  • /bin/sh : It is executable path of the system shell.
  • read : It will read the data from user.

Now, save and run this file using terminal.

$ chmod +x ./
$ ./

Note : Where,

  • chmod +x : It is used to make file executable.
  • ./welcome : Here, “./” will run the bash script file.

Output : 

Output Of above bash script

Here, we can see clearly that how to run bash script in terminal.

My Personal Notes arrow_drop_up
Last Updated : 28 Nov, 2021
Like Article
Save Article
Similar Reads
Related Tutorials