我正在尝试在 tomcat webapp 中安装一些东西。这是我的install目标的开始:
tomcat=`locate --regex "^(/var/lib/tomcat[0-9]{1,2}/webapps/[^/]+/)AppName\.html$" -l 1 | tr -d "\n"`
echo "Tomcat: $tomcat"
# If the string is empty (no path matched) or the path does not exists (that should never really happen)
# terminate
if [ -z "$tomcat" ] || [ ! -f "$tomcat" ]; then
echo "Application not found on filesystem."
exit 404
fi
Run Code Online (Sandbox Code Playgroud)
然而,这是输出:
tomcat=`locate --regex "^(/var/lib/tomcat[0-9]{1,2}/webapps/[^/]+/)AppName\.html -l 1 | tr -d "\n"`
/bin/sh: 1: Syntax error: Unterminated quoted string
makefile:77: recipe for target 'install' failed
make: *** [install] Error 2
Run Code Online (Sandbox Code Playgroud)
其他人都声称您可以使用`(反引号)将命令stdout输出分配给变量。我什至曾经tr -d "\n"删除所有换行符,也许它们会出现。并且代码在 shell 中完美运行:
XXXXX@debianvirtualbox:~$ tomcat=`locate --regex "^(/var/lib/tomcat[0-9]{1,2}/webapps/[^/]+/)AppName\.html$" -l 1 | tr -d "\n"`
XXXXX@debianvirtualbox:~$ echo $tomcat
/var/lib/tomcat8/webapps/websight/AppName.html
Run Code Online (Sandbox Code Playgroud)
还有什么需要修复的吗?
$符号在 makefile 中因引起麻烦而臭名昭著,因为它们被解释为变量标记。这里只需将第一行中的值加倍就可以了:
AppName\.html$$"
Run Code Online (Sandbox Code Playgroud)
另请参阅其他帖子以了解有关 makefile 转义问题的更多信息。
| 归档时间: |
|
| 查看次数: |
9235 次 |
| 最近记录: |