Linux shell script execution error: bad substitution [How to Solve]

the script content is as follows:

string="This is a string!"
echo ${string:1:4}

Bad substitution: after adding executable permission

cause analysis:

It has to do with whether the linux shell uses /bin/sh or /bin/bash.
My script specifies sh, and ubuntu's sh is connected to point to dash, not bash, so debugging leads to error messages.


string="This is a string!"
echo ${string:1:4}

Read More:

The most commonly used shells in Linux are the Bourne shell (sh), the C shell (csh), and the Korn shell (ksh).

The Bourne shell is the original shell used by Unix and is available on every Unix. the Bourne shell is quite good at shell programming, but does not do as good a job as several other shells at handling interaction with the user.
The default shell for Linux operating systems is the Bourne Again shell, which is an extension of the Bourne shell, or Bash for short, and is fully backward compatible with the Bourne shell and adds and enhances many features to the Bourne shell. bash is placed in /bin/bash and it has many features that provide functions such as command completion, command editing, and command history tables. It also contains many of the advantages of the C shell and the Korn shell, and has a flexible and powerful programming interface, while having a very user-friendly 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 ported bash from NetBSD to Linux and renamed it to dash (Debian Almquist Shell), and suggested that / Ubuntu claims that since they did this in 6.10, there has been a significant increase in boot speed.

Similar Posts: