Linux shell script execution error: bad substitution

Source: Internet
Author: User

Script test.sh content:

#!/bin/bash
Read Presskeyindexes=0c=${presskey:indexes:1} is executed using debug mode: Sh-x test.sh 3rd line always appears bad substitution prompt information. Best of all: So Baidu, find a useful information, which is used by the Linux shell is/bin/sh, or/bin/bash has a relationship. The/bin/bash shell is specified in my script, but I use the SH shell when I debug, so I debug with an error message. Workaround: Use bash-x test.sh for debugging, then success. The following is a reference to the linked content: Http://hi.baidu.com/wwkblog/item/c974569b9ee031aecd80e5fe

It is always an error to execute the following script on LinuxMint:

123 #!bin/sha="abcdefghijklmn"echo${a:2:7}

Then run SH 1.sh always quote bad substitutation

Later changed into

123 #!bin/basha="abcdefghijklmn"echo ${a:2:7}

Then execute bash 1.sh with no problem.

The reason is that Ubuntu sh is connected to dash instead of bash, and naturally in identifying ${a:2:7} always goes wrong.

There are several types of shells in the

   linux, the most common of which are Bourne   shell (SH), c    Shell (CSH) and Korn   shell (Ksh). Each of the three shells has advantages and disadvantages. Bourne   shell is the first shell used by UNIX and can be used on every UNIX type. Bourne   shell is very good at Shell programming, but does not work as well as several other shells in dealing with user interactions. Linux OS default shell is Bourne   again   shell, it is the extension of Bourne   shell, For short, bash is completely backwards compatible with Bourne   shell and adds and enhances many features on the basis of Bourne   shell. Bash is placed in/bin/bash, which has many features, such as command completion, command editing, and command history tables, and it also contains a lot of C   shell and korn    The advantages of the shell are flexible and powerful programming interfaces while having a friendly user interface.

/bin/sh in the Gnu/linux operating system is a symbolic link to bash (Bourne-again Shell), but given that bash is too complex, someone transplanted ash from NetBSD to Linux and renamed it dash (Debian Almquis T Shell), and it is recommended to point/bin/sh to it for faster script execution. Ubuntu claims that since they did so in the 6.10 edition, the system boot speed has been significantly improved. The Debian program also takes dash as the default/bin/sh in the next release (codenamed Lenny).

Linux shell script execution error: bad substitution

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.