0

I have had a long history of not being able to run .sh files. I don't understand what the underlying problem is,(I'm a little bit new to Ubuntu/UNIX based systems). When I try to run certain .sh scripts I get the following error, accompanied by the Ubuntu Software Center starting up:

"The file "/home/user/Downloads/netbeans-8.1-cpp-linux-x86.sh" could not be opened."

As a clarification, I have been double clicking directly on the .sh file in the file system.

3 Answers3

2

To install a sh script you need to type some commands. Double-clicking on it won't always work. So, first, open a terminal, then open your file manager and navigate to the location of your sh script.

  1. Now, type the following command (edit the relevant parts) in your terminal:

    chmod a+x DRAG THE SH SCRIPT AND DROP IT HERE
    

Note: As pointed out by kos, this is done, so that if at any time you wish to run it as below, then, you won't face any error.

./path/to/script
  1. Next, type this:

    sh DRAG THE SH SCRIPT AND DROP IT HERE
    

If there are any errors such as Permission Denied, then run the script as root:

sudo sh DRAG THE SH SCRIPT AND DROP IT HERE
Raphael
  • 8,135
1

There are two reasons why a simple script on linux may not execute:

  1. The path is not correct. Unlike Windows, the current directory is not in the search path of the shell. So, to call a script in the current directory, you have to specify the current directory with the dot . before the name of the script: ./script.sh. Alternatively you can specify the full path: /home/user/script.sh

  2. The script file is missing. Or it is under a different path. This the same as above.

You can execute scripts in two ways:

  1. specify the name (with path) on the commandline. And - if the permissions are correct - the file will be run with the shell (if the shebang is correct)

  2. use the shell command sh and specify the script as argument. Then, it's not necessary to specify the path, however the shell needs to be able to find the script. You would execute a script in the current directory like this: sh script.sh

user23573
  • 515
-4

Try the command "chmod 777 " and then your file name. To run enter the name of your sh file with a ./ in front of it. Expempli gratia: chmod 777 coolman.sh ./coolman.sh