16

I'm trying to install VMware Workstation in my Ubuntu 12.04.2 LTS. If I execute the following command:

sudo ./VMware-Workstation-9.0.1-894247.x86_64.bundle

it finishes at once and the installation never starts.

If I execute this command:

sudo sh ./VMware-Workstation-9.0.1-894247.x86_64.bundle

The installer can be launched successfully.

Why does this make a difference?

Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83
Landy
  • 163
  • related: http://askubuntu.com/questions/141928/what-is-difference-between-bin-sh-and-bin-bash – Takkat Apr 11 '13 at 08:40
  • related as well: http://askubuntu.com/questions/70534/difference-between-su-sudo-s-sudo-i – Nanne Apr 11 '13 at 08:54

3 Answers3

18

If the file is not marked as executable you need to call a command shell interpreter to execute it.

Examples:

  • sudo sh foo will open foo with sh using sudo privileges.

  • sudo bash foo will open foo with bash using sudo privileges.

  • sh foo will open foo with sh using your user's privileges.

  • bash foo will open foo with bash using your user's privileges.

If you mark a file as executable you just need to call it with ./foo and because it is marked as such it will be read with the defined command shell interpreter and executed without the need to define one.

ls -F will list files and mark executables with *.

To enable the execute bit on a file (and make it executable as such) use the command chmod +x foo.

In your case to make the file you are using executable you would then use the command

chmod +x VMware-Workstation-9.0.1-894247.x86_64.bundle

and then you will be able to run it with either

sudo sh ./VMware-Workstation-9.0.1-894247.x86_64.bundle or just by typing sudo ./VMware-Workstation-9.0.1-894247.x86_64.bundle.

Bruno Pereira
  • 73,643
15

Sh is a shell for running commands, so executing sh with sudo gives you a root shell. This means all commands in that shell are executed as root. My guess is that script executes something else that needs root, however when you only use sudo not sudo sh, that something else gets executed as a normal user, however with sh everything will be executed as root.

0

sudo is a command that give you root privilege. But sh is an interpreter. When you use sudo command, you running the command as root privilege. But when you use sudo sh command, you running the sh command as root.

sbh
  • 11
  • in this case, command is a path, meaning bash (the current shell) will run it if it has the executable bit set, and assuming it doesn't begin with an interpreter directive specifying another interpreter (like #!/bin/sh). The script may not work without sh because it does not have the executable bit set (likely, although one gets an error in this case), or it may be incompatible with Bash (unlikely, and this produces an error too, usually). The other answers here don't seem very illuminating... – Zanna May 17 '21 at 14:00