linux shell脚本执行错误:bad substitution
脚本test.sh内容:
#!/bin/bash
str1="this is a great site"
echo ${str1:1:3}
使用调试方式执行:sh -x test.sh第3行总出现bad substitution提示信息,这与linux shell使用的是/bin/sh,还是/bin/bash有关系。我的脚本中指定使用的是/bin/bash shell,但是我在调试的时候使用的是sh shell,因此调试时导致错误提示信息。
解决方法:
使用bash -x test.sh进行调试,则成功。
bash ./test.sh 则运行成功