Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm really new to using terminal and I've been following guide blindly without knowing why is that there and what does it do..though this guides help me in installing the vmware player.

this one worked for me since making the file executable, clicking the file, and run..only say root access is needed.

sudo sh vmwareplayer.txt (renamed it to be shorter)

Somehow I know what sudo does but what does sh do? Without it it goes "vmwareplayer.txt not found". And for bundle files why does it end with .txt?

share|improve this question
    
It is a language interpreter –  Tachyons Mar 3 '13 at 17:19
    
@Tachyons If you know the answer to the question, explain it in more detail and post it as an answer! :) –  Alvar Mar 3 '13 at 17:27
    
See also a related question with answers explaining in great depth about interpreters (such as sh, bash) and shebangs, etc. –  user76204 Mar 3 '13 at 18:55
1  
@Mik This is not a duplicate of that question. This is asking what sh does in a command that invokes a script. That question is about how a #! works inside a script file. Totally different. –  Eliah Kagan Mar 4 '13 at 9:13
    
@EliahKagan Yes, I was probably too hasty to cite it as a duplicate: I should have put 'related, but not duplicate' when referring to the other answer. You are right as usual; if you want to ask a moderator to reopen that's fine. I've already voted to reopen. –  user76204 Mar 4 '13 at 18:13

4 Answers 4

In Ubuntu, sh or /bin/sh just points to dash. sh is supposed to run default command interpreter, which is dash for Ubuntu.1 dash refers to Debian Almquist shell.

A shell is a command line interpreter for the system. There are several other shells like bash, csh, zsh etc. Here is a brief excerpt from man page of dash:

 The shell is a command that reads lines from either a file or the termi‐
 nal, interprets them, and generally executes other commands.  It is the
 program that is running when a user logs into the system (although a user
 can select a different shell with the chsh(1) command).  The shell imple‐
 ments a language that has flow control constructs, a macro facility that
 provides a variety of features in addition to data storage, along with
 built in history and line editing capabilities.  It incorporates many
 features to aid interactive use and has the advantage that the interpre‐
 tative language is common to both interactive and non-interactive use
 (shell scripts).  That is, commands can be typed directly to the running
 shell or can be put into a file and the file can be executed directly by
 the shell.

There are lot of tutorials about Linux shells, you can start with this Wikipedia Article.

Coming to your question, if you write sh file, dash executes file for you.

share|improve this answer
    
It' a good explanation what sh is, but not what it does in the specific question above. –  NilsB Mar 3 '13 at 18:01
    
Added some more information, it should be sufficient now –  IgnitE Mar 3 '13 at 18:26

sh stands for "shell" and shell is the old, Unix like command line interpreter. An interpreter is an program that executes specific instructions written in a programming or scripting language. So basically you say "Execute that file for me".

You must understand that Linux doesn't really look at the file extension in order to determine what the file (or program) is. So as long as the content of that file is written in a way that the sh interpreter understands, it will work. But just for the sake of readability, such files are normally given an .sh extension and I have no idea what the developer was thinking when he gave that file a .txt extension..

share|improve this answer

Just a word of comment:

sudo executes a command with root privileges. When you call sudo vmwareplayer.txt which clearly means "run command vmwareplayer.txt with root access" and fails, because there is no such program.

sudo sh command means "execute sh command with root privileges"

and sh command will execute a command under Bourne shell.

New question arises. What are shells? This is a longer question and you will find some info on wiki I suppose.

Meanwhile, remember man is your best friend.

share|improve this answer

I believe that none of the earlier responders answered the question you actually asked G., so I'll take a shot at it. Interposing the sh when executing a program as you mentioned, executes the program in a non-interactive subshell. Non-interactive shells behave differently (e.g. initialisation) from the standard interactive shell you were using when you ran the program.

Honestly I don't know what practical effect this has. As you noticed sh vmwareplayer.txt is (usually) able to execute something in the same folder, where simply typing vmwareplayer.txt (usually) will not. That has to do shell environment; it isn't any quality native to the shell or subshell itself. You can of course directly execute a program in the current directory as root: sudo ./vmwareplayer.txt. In my experience this always works just as well as sudo sh vmwareplayer.txt. I was hoping someone would come along and explain why the subshell was sometimes desirable.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.