Linux script files are very useful to execute multiple commands again and again. They are a very practical way to executed multiple commands. But in order to run a script file, it should be executable. By default when a script file is created it is not executable. In order to make it executable, the chmod command should be used.
chmod Command Syntax
The chmod command has the following syntax.
chmod PERMISSION FILE
- PERMISSON is the execute permission which will be set fr the FILE. The execute permission can be expressed as u+x . This means the user can execute the specified script file.
- FILE is the script file we want to make executable.
Make Bash Script Executable
A script file can be made executable with the chmod command. In the following example, we will make the script file named commands.sh executable. The following command makes the script file executable for the script file owner.
chmod u+x commands.sh
Alternatively the +x can be used to make given script file executable for every one. The script file owner, group and others can execute the specified script file.
chmod +x commands.sh
Make Bash Script Executable via GUI
Even Linux is managed mostly with the command line interface it also provides GUI via different desktop environments. A script file can be made executable by using file managers for different desktop environments like GNOME, Xfce, KDE, etc. Right-click to the script file and select the Properties.
In the following script file properties we wil enable or check the “Allow executing file as program”. but this xan be change in different desktop environments as this desktop environment is Gnome.
Execute Bash Script
The bash script can be executed in different ways. The most basic way is specifying the script name with its full or absolute path.
Alternatively if the script file is located under the current working directory we can specify the script file name directly like below. The dot is used to specify the current working directory.