使用bash时替换错误
这是我的密码使用bash时替换错误,bash,netcat,Bash,Netcat,这是我的密码 #/bin/bash PING_STATUS=“${netcat-vz mc.bella.wtf 25565}” curl-H“Content-Type:application/json”-X POST-d'{“embeddes”:[{“title”:“Server Status:”,“color”:16027903,“description:““$PING_Status”'“}]}'”$WEBHOOK” 我在运行它时得到这个 mc@ubuntu:~$serverping ./s
#/bin/bash
PING_STATUS=“${netcat-vz mc.bella.wtf 25565}”
curl-H“Content-Type:application/json”-X POST-d'{“embeddes”:[{“title”:“Server Status:”,“color”:16027903,“description:““$PING_Status”'“}]}'”$WEBHOOK”
我在运行它时得到这个
mc@ubuntu:~$serverping
./server/server/ping:第3行:${netcat-vz mc.bella.wtf 25565}:替换错误
我已经尝试过转义-
和
以确保
编辑:已解决
我不得不用()而不是{}你是说
$(…)
而不是${…}
${…}
用于变量替换,$(…)
用于运行命令并替换其输出。这解决了问题,但现在当它运行时,输出对bash来说什么都不是?netcat
的详细输出(-v
)将转到stderr,因此您需要附加2>&1
来捕获它。这很有效,非常感谢。