33 Votes

Linux Batch Script does not execute

Question by Guest | Last update on 2023-02-17 | Created on 2016-06-07

According to an Internet tutorial, I have tried to create my first Linux batch test script today.

For this, I have created a text file with the name "script" containing the following content on my desktop:

#!/bin/bash

echo TEST

After that, I opened the terminal (CTRL + ALT + T), changed in the corresponding directory (cd Desktop) and tried the following command:

./script

The instruction in the Internet stated that with this, the script should be executed. So, the word "TEST" should appear in the terminal.

Unfortunately, it has not worked. Instead, I only got the error message "bash: ./script: Permission denied".

What is the reason for that? How to execute my script? It should be that simple, isn't it?

ReplyPositiveNegative
3Best Answer3 Votes

Your file must be marked as executable with chmod (Change Mode) before you can execute it.

For this, just enter the following command into the terminal, where "script" is the name/path of your script file:

chmod +x script

After that, you should be able to run the script with the following command:

./script

The background: When typing "ll" (two lowercase L) into the terminal, you get a list of all files. Each file has specific rights for specific user groups (for example r for read or w for write). After the command "ll", you can see those rights directly before the files.

Here, you can also see whether the x flag is set (x is standing for executable). With chmod, you can change the file rights or flags. "chmod +x" is adding the "x", "chmod -x" is removing the "x". In the same way, you can also modify the write permission with "chmod +w" and "chmod -w" or the read permission with "r".

You can learn more about this topic in the tutorial about making script and program files as executables on Linux.
Last update on 2023-02-17 | Created on 2016-06-07

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.