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 則運行成功