Alpine Linux 中带有转义字符的 if 语句(ash busybox)
我有简单的脚本来准备文件,并且它按预期工作。所有代码都在 docker image alpine:latest 执行(所以 ash busybox)
echo "credentials \"url.com\" {token = \"${VALUE}\"}" > ~/.terraformrc
稍后我想准备测试,我正在使用 if [[ ]] 语法。
if [[ $(cat ~/.terraformrc) != "credentials \"url.com\" {token =\"VALUE\" }" ]]; then exit 1; fi
在 Bash 测试有效,但在 ash/busybox/alpine 上,
sh: "url.com": unknown operand
当我 echo all 时,我也会在 ash/busybox/alpine 上正确转义
echo "credentials \"url.com\" {token = \"VALUE\" }"
credentials "url.com" {token = "VALUE" }
我应该如何在 [ ] 或 [[ ]] 内转义 " ? 谢谢帮助
I have simple script to prepare file and it is working as intended. All code is executed at docker image alpine:latest (so ash busybox)
echo "credentials \"url.com\" {token = \"${VALUE}\"}" > ~/.terraformrc
Later I want to prepare test and I am using if [[ ]] syntax for that.
if [[ $(cat ~/.terraformrc) != "credentials \"url.com\" {token =\"VALUE\" }" ]]; then exit 1; fi
On Bash test is working but on ash/busybox/alpine I get
sh: "url.com": unknown operand
Also on ash/busybox/alpine when I do echo all is escaping correctly
echo "credentials \"url.com\" {token = \"VALUE\" }"
credentials "url.com" {token = "VALUE" }
How should I escape " inside [ ] or [[ ]] ?
Thx for help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[[ ]]
用于 bash,对于 ash 你应该使用 POSIX[ ]
代替:顺便说一句,你正确地进行了转义,但你忘记了双引号
$ (cat ~/.terraformrc)
[[ ]]
is for bash, for ash you should use POSIX[ ]
instead:BTW, you were doing the escaping correctly but you forgot to double quote
$(cat ~/.terraformrc)