How to run shell scripts


Contents:

General information

Please read this first.

This page is meant to help users how to run shell scripts on their Unix-like system. The projects that consist of shell scripts do not run on Windows.

As a matter of fact, the projects consisting of shell scripts provided by this website were developed on (and also for) the Bash shell, which is the default shell on many Unix-like systems. They may also work with other shells, however, there is no guarantee for that. Due to this, these projects include a shell compatibility check script.


Please do not contact me to ask how to run shell scripts on your system that are not a part of any of the projects provided by this website.

If you need any help you may search the internet (e. g. official documentation, how-to pages and forums) or ask someone who is using the same operating system.


Run shell scripts on Unix-like systems

How to run shell scripts on Unix-like systems (such as Linux and BSD derivatives).

The following example shows how to run a shell script named foobar.sh on the shell. In this example, the script file is located in the /home/johndoe directory.


If a shell script requires command-line arguments to operate, simply double-clicking on the script file will not work.

Due to this, such scripts need to be executed either using the shell, a shell script or a shortcut which contains all the required arguments.

Absolute path

You can simply run the script by typing:


$ /home/johndoe/foobar.sh

If you get some sort of "permission denied" message, you can make the file executable via

$ chmod +x /home/johndoe/foobar.sh

and retry.


Relative path

If you are inside the directory where the script file is located, you can type ./ instead of the full path to the script. This refers to the current path on the shell. For example:


$ ./foobar.sh

If you get some sort of "permission denied" message, you can make the file executable via

$ chmod +x foobar.sh

and retry.