How to execute a shell script in Linux

I am a new Linux system user. How do I execute a shell script in Linux? How do I write and execute a shell script on Linux system?

This page shows various steps to write and execute a shell script in Linux using the Terminal window or app.

Steps to execute a shell script in Linux

The procedure is as follows:

  1. Create a new file called using a text editor such as nano or vi in Linux: nano
  2. Add the following code:
    echo "Hello World"
  3. Set the script executable permission by running chmod command in Linux: chmod +x
  4. Execute a shell script in Linux: ./

Let us see all steps in details.

Step 1 – Open the terminal

To write a shell script, open the terminal app. Hit the keyboard shortcut Ctrl-Alt+T:

Step 2 – Write the shell script using an editor

Type the following command to write a shell script:

Creating your first shell script named

Add the following code:
# My first shell script
echo "Hello $USER"
echo "Today is $(date)"
echo "Bye for now"

To Save and close the file in nano press CTRL+X and when prompted choose Y (Yes) to save the file and followed by the Enter key:

Writing your first shell script

Step 3 – Make the shell script executable

Let us verify newly created file, run [nicmd name=”ls”] and cat command:
ls -l

To set executable permission, run the following chmod command:
chmod +x
Verify permissions:
ls -l

Give execute permission to your script on Linux

Step 4 – Execute the shell script in Linux

Now we have shell script named But, how do you run it? Try:
The . refers to the current directory. Another option is to specify the full path:

Executing a shell script in Linux


For more info see Linux Shell Scripting Tutorial and bash command man page:
man bash
help read

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Tristan May 11, 2017 @ 8:05

    How do you execute .sh in Linux?
    Give execute permission to the script:
    chmod +x /path/to/
    To run your script:

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @