Answers:
用
"$filepath"_newstap.sh
要么
${filepath}_newstap.sh
要么
$filepath\_newstap.sh
_是标识符中的有效字符。点不是,因此shell尝试进行插值$filepath_newstap。
您可以使用set -u,使外壳的出口与一个错误,当你引用一个未定义的变量。
${}双引号和双引号有什么区别?我应该优先选择另一个吗?
在变量名周围使用花括号:
`tail -1 ${filepath}_newstap.sh`
$filepath_newstap.sh被解释为解决问题的方法,${filepath_newstap}.sh而不是预期${filepath}_newstap.sh的问题。
set -u如果引用未定义的变量,它将导致脚本中止。