Variable interpolation in the shell
Use curly braces around the variable name:
`tail -1 ${filepath}_newstap.sh`
Use
"$filepath"_newstap.sh
or
${filepath}_newstap.sh
or
$filepath\_newstap.sh
_
is a valid character in identifiers. Dot is not, so the shell tried to interpolate $filepath_newstap
.
You can use set -u
to make the shell exit with an error when you reference an undefined variable.