【发布时间】:2016-06-22 04:55:11
【问题描述】:
有什么方法可以在不使用单引号或双引号的情况下回显字符串。这是我的问题。
如果我有一个包含以下内容的 bash 脚本,它会按预期工作。
./node_modules/.bin/json -I -f ./test.json -e 'console.log("thomas")'
我正在尝试使用该确切代码,但我无法以任何方式更改它。我正在尝试在一个命令中将其作为字符串执行。
我尝试将 string-to-echo 用单引号和双引号括起来,但由于代码同时包含单引号和双引号,因此无法正确执行。
echo './node_modules/.bin/json -I -f ./test.json -e 'console.log("thomas")'' | sh
echo "./node_modules/.bin/json -I -f ./test.json -e 'console.log("thomas")'" | sh
有什么方法可以在一行中执行上面的代码并将其传递给sh?
【问题讨论】:
-
@Cyrus 我不想逃避字符串。当它在文件中时它是有效的代码!
-
你不能
cmd | sh吗? -
./node_modules/.bin/json -I -f ./test.json -e 'console.log("thomas")'的输出是什么? -
这个字符串可以是一个完整的 bash 文件,应该可以这样运行。 @anubhava 输出有什么关系?
-
那你就不能用
./node_modules/.bin/json -I -f ./test.json -e 'console.log("thomas")' | bash吗?