You can open or run .sh file in the terminal on Linux or Unix-like system. The .sh file is nothing but the shell script to install given application or to perform other tasks under Linux and UNIX like operating systems. The easiest way to run .sh shell script in Linux or UNIX is to type the following commands. Open the terminal (your shell prompt) and type the commands.
|Requirements||Linux or Unix-like systems|
How do I run .sh file shell script in Linux?
The procedure to run the .sh file shell script on Linux is as follows:
- Set execute permission on your script:
chmod +x script-name-here.sh
- To run your script, enter:
Another option is as follows to execute shell script:
The syntax is:
How to run .sh file as root user
Some time you need root access to install application; without root, you won’t have the necessary permissions to install application or make system level modifications. Root access is disabled by default on many Linux and UNIX like systems. Simply use the sudo or su command as follows:
sudo bash filename.sh
Type your password. Another option is to use the su command as follows to become superuser:
Type root user password and finally run your script:
How to use chmod command to run .sh shell script in Linux
Another recommend option is to set an executable permission using the chmod command as follows:
chmod +x file.sh
Now your can run your .sh file as follows
How do I run .sh file named install.sh?
Just run the following two command:
chmod +x install.sh
The dot (.) refers to the current working directory. The install.sh is in the current directory so you run it as above or as follows too:
GUI method to run .sh file
- Select the file using mouse.
- Right-click on the file.
- Choose Properties:
- Click Permissions tab.
- Select Allow executing file as a program:
- Now click the file name and you will be prompted. Select “Run in the terminal” and it will get executed in the terminal.
Running .sh file shell script and debugging options
Pass the -x to debug shell script when running on your system. It print commands and their arguments as they are executed. For example:
bash -x script-name.sh
sh -x script-name.sh
Want to show shell input lines as they are read. Try passing the -v option:
bash -v script-name
We can combine both options. In other words, try it as follows:
bash -x -v backup.sh
For more information see how to improve your bash/sh shell script with ShellCheck lint script analysis tool and other bash debugging hints here.
You learned how to run .sh file shell script using combination of the chomod and dot (.) or sh/bash command. We can use any one of the following command execute shell script on Linux and Unix-like systems:
bash script.sh sh my-script.sh ## or chmod +x /path/to/script/file /path/to/script/file
See the following resources for more info:
🐧 53 comments so far... add one ↓
|Category||List of Unix and Linux commands|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|