Ubuntu Shell script Run exception: The difference between bash and dash

Source: Internet
Author: User

Under Ubuntu I wrote a shell script with bash to grammar (exactly the script on the computer), under Ubuntu, with SH test.sh to run, but there are unexpected results, such as ECHO-E "\ntest\n" to the execution is different, Run directly with the SH test.sh, the-E (as a string) is printed, and the Echo-e "\ntest\n" is not output "-e" directly in the terminal.

I was wondering what the reason was, and then finally found out that Ubuntu under the SH default point to dash.

Echo $SHELL-/bin/bash

Type SH--/bin/sh

Then I went to/bin under the "SH-and Dash", the original SH is/bin/dash link.

Google later discovered that buntu6.10 has replaced the previous default Bashshell for Dash. Its performance is/bin/sh link to/bin/dash rather than traditional/bin/bash.

Bash-gnu Bourne-again SHell

Dash-debian Almquist Shell

You can look at the man Bash/man Dash separately.

So how do you change sh to point to bash?

The most violent approach, of course, is to change/bin/sh's soft links directly into bash,

such as: Ln-s/bin/bash/bin/sh

However, there are some elegant methods,

sudo dpkg-reconfigure Dash

When the menu asks you if you want to dash, you can choose No.

Check again, Ls/bin/sh-al found that the soft link points to/bin/bash.

Ubuntu Shell script Run exception: The difference between bash and dash

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.