Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two questions :

  1. What is the difference between executing sh and
  2. How can I make both of them giving me the same output ?

I'm asking this question as right now I'm facing a problem. I'm trying to run a Java + SWT application from terminal.

When I do, it gives me the desired output. But when I do sh or bash, it throws me an error :

Exception in thread "main" java.lang.NoClassDefFoundError: MainForm/java
Caused by: java.lang.ClassNotFoundException:
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
Could not find the main class:  Program will exit.

I know this question is already asked here but I'm still not clear about it.

I have gone through the following links :

What is the difference between ./ and sh to run a script?

Can scripts run even when they are not set as executable?

Can anyone help me with this?

share|improve this question
If the script is not too long could you maybe post it? Pastebin is also ok – Gerhard Burger Dec 7 '12 at 18:29

The script probably knows which shell it should be running in. The first line might be something like


If you run it with sh, the first line (a.k.a. shebang) is ignored. A different shell tries to run the script, but does not understand it - it is like running Java code in Pascal. If you run it with the right shell, it should behave identically:

share|improve this answer
Do you mean the 1st line of my – RAS Oct 16 '12 at 10:33
@RAS: Yes, exactly. – choroba Oct 16 '12 at 10:34
First line of my is java -classpath .:jars – RAS Oct 16 '12 at 10:57
@RAS: Hm... what output do you get if you run sh in a terminal? – choroba Oct 16 '12 at 10:58
Exception mentioned in the question. – RAS Oct 16 '12 at 11:10

By putting bash or sh before your file, you force to use this shell to execute your file. So it's better to use the first line of the file :


So every time you execute your file it will be with the same shell.

And for your second question, no, you need to make a script executable to run it :

chmod +x
share|improve this answer
You mean giving permission for "Execute : Allow executing file as program" ? – RAS Oct 16 '12 at 11:49
I'm not familiar with GUI, I was talking about a command you have to type in Terminal. But it sounds like the same thing, so give that a try. – NorTicUs Oct 16 '12 at 11:57
I asked you this as I already have gone through this link : – RAS Oct 16 '12 at 12:02
That's it. So what's your point ? – NorTicUs Oct 16 '12 at 12:14
When I do sh or bash, it throws me an error. – RAS Oct 16 '12 at 12:24

Your Answer


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.