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
$ sh
Enter the pattern to be searched: 
$ ./
Enter the pattern to be searched: \c

Contents of script

$ cat
#!/bin/bash interactive version uses read to take input

echo "Enter the pattern to be searched: \c"
read pname
echo "Enter the file to be used: \c"
read flname
echo "searching for the pattern $pname from the file $flname"
grep "$pname" $flname
echo "Selected records are shown above"

Provide me why their is difference in first line why \c is their in second line.

$ sh
Enter the pattern to be searched: 
$ ./
Enter the pattern to be searched: \c
share|improve this question
That script is wrong both as an sh-script and as a bash-script. As an sh script, printf should be used instead of echo. As a bash script, read's -p should be used instead of echo. E.g. read -ep "Enter file to be used: " flname – geirha Jan 8 '14 at 22:18

There are two different shells in fact. One is /bin/bash and other is /bin/dash. And /bin/sh is actually a softlink of /bin/dash. To verify it, write in terminal,

which sh

you will get output: /bin/sh

Next type ls -l /bin/sh in terminal, which will return something like,

lrwxrwxrwx 1 root root 4 May 16 20:23 /bin/sh -> dash

Which shows the fact that sh is a softlink of /bin/dash. you can try further which dash.

Actually bash is sh with more features and better syntax. Both of them have almost same commands, but they are different.

What is happening here

When you are running sh then script is handled by dash but when you run ./ due to the shebang line(#!/bin/bash) on top of the script bash shell handles it. So you get slight different formatting in output. Keep in mind bash has some improved syntax.

share|improve this answer

The output is different because you are using two different programs.

In the first case sh you start a program named sh and tell it to execute the instructions in That program sh is probably the bourne shell (sh), a bourne again shell (bash) trying to emulate the classic shell (and thus reacting differently from its native mode), dash or even anything else.

When you use ./ you try to execute the script itself. Its first line contains a shebang and an interpreter (#!/bin/bash) telling it that it needs to use bash (and all its features).

That means you use a different program/mode than in the first case. And you get different output.

To verify this, try one of these two:

  • /bin/bash (which should produce the same output as the ./
  • Or change the first line to #!/bin/sh.
share|improve this answer
/bin/sh is a POSIX shell in modern UNIX and UNIX-like systems. You luckily don't see bourne as /bin/sh much anymore. In the case of Ubuntu, dash is used as sh by default. – geirha Jan 8 '14 at 22:04

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.