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.

patrickhuie19
  • 13
  • 1
  • 6

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,035
  • that did work, so thanks!

    however, I am told the following error: /tmp/.nbi-5122111.tmp/_jvm/lib/i386/libawt_xawt.so: libXtst.so.6: cannot open shared object file: No such file or directory

    I was also told that i was using the wrong platform (it said x32 instead of x64), however, I redownloaded the program again, made sure I got the x64 bit system, and got the same error.

    – patrickhuie19 Dec 26 '15 at 03:22
  • @patrickhuie19 - Did you install java previously? – Raphael Dec 26 '15 at 04:14
  • If you're going to run the script with sh /path/to/script.sh it's unuseful to chmod it, sh /path/to/script.sh will run the script even if it's not executable. chmod is useful to run the script like so: ./path/to/script – kos Dec 26 '15 at 06:19
  • @kos - Thanks kos! I am new to linux! Still learning. Will edit my answer. – Raphael Dec 26 '15 at 06:20
  • Since you're learning - in this case what you're suggesting is fine because the script is to be run in Dash, but be aware that sh foo will run foo in Dash regardless, i.e. overriding a potential shebang. I.e. a script meant to be run in Bash will be run in Dash (and maybe break). ./foo instead will always read the shebang and the script will always be run in the right interpreter. It's worth nothing that if the script doesn't have a shebang at all the only way to run the script is specifying the interpreter in which it's to be run: sh foo :) – kos Dec 26 '15 at 06:37
  • @patrickhuie19 Please ask another question for your follow-up issue. – kos Dec 26 '15 at 06:38
  • @kos - Would you mind if I open a chat room with you and ask a few questions? – Raphael Dec 26 '15 at 06:41
  • Nope, it's holidays, nothing to do. :) Even the general room is empty, I'm currently in there. Either drop by there or send me the link to the room. – kos Dec 26 '15 at 06:45
  • @kos - http://chat.stackexchange.com/rooms/33453/doubt-session-with-kos Please join. – Raphael Dec 26 '15 at 06:50
  • @Raphael - I have installed the latest java version. I remember when I was trying to get eclipse installed properly, I had to do quite a bit of command line work, as well as when I was trying to install android studio. Does this remind you of a problem you've faced before? – patrickhuie19 Dec 27 '15 at 18:50
  • @patrickhuie19 - Installing eclipse is the easiest of them all. Maybe one of the reason as to why I use it more frequently. And I haven't used Android Studio before so cannot help. – Raphael Dec 28 '15 at 05:16
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
  • 1
  • 5
  • 19
-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