The difference between/bin/sh and/bin/bash

Source: Internet
Author: User
Tags posix

I had a problem learning Linux today.

#!/bin/sh
# test.sh

username= ' HCBBT '
echo ' My name is ${username}. Call me ${username:0:1}-chan. "

This script runs directly to the Times wrong:/test.sh:5:./test.sh:bad substitution.
Toss, found that the first line of the interpreter changed to/bin/bash is no problem.

So I checked the difference between/bin/sh and/bin/bash, using: Intercept the string is not POSIX standard. The difference between SH is generally set to bash the soft chain (symlink)

Ls-l/bin/sh
lrwxrwxrwx 1 root 4 Sep 04:45/bin/sh-> Dash

In a typical Linux system (exceptions such as FREEBSD,OPENBSD, etc.), using the SH call execution script is equivalent to opening bash's POSIX Standard mode means that/bin/sh is equivalent to/bin/bash--posix

Therefore, the differences between them come from the POSIX standard mode and bash differences, such as: intercepting the string, not using let, interrupted by the error, and so on, when used in need of attention. Reference [difference between SH and bash] http://stackoverflow.com/questions/5725296/difference-between-sh-and-bash [/bin/ The difference between bash and/bin/sh] http://www.cppblog.com/erran/archive/2012/05/24/176038.aspx [#!/bin/sh and #!/bin/bash] http:// Fanli7.net/a/bianchengyuyan/_net/20130916/424894.html

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.