嗨,我对 bash 和一般编码来说绝对是新手。我有一个想要执行的屏幕命令。我已经在屏幕“ftb”上运行 Minecraft 控制台:
screen -S ftb -p 0 -X stuff "tellraw @p ["",{"text":"This is a text!","bold":true,"color":"gold"},{"text":"\n"},{"text":"More text to be seen here!"},{"text":"\n"},{"text":"HAVE SOME TEXT IN UR FACE!","color":"green","clickEvent":{"action":"open_url","value":"https://google.com"}},{"text":"\n"},{"text":"Have Fun!"}]"
但该命令会与所有引号混淆。到目前为止我已经尝试过了,但没有运气......
#! /bin/sh
say_this()
{
screen -S ftb -p 0 -X stuff "$1^M"
}
say_this "tellraw @p ["",{"text":"This is a text!","bold":true,"color":"gold"},{"text":"\n"},{"text":"More text to be seen here!"},{"text":"\n"},{"text":"HAVE SOME TEXT IN UR FACE!","color":"green","clickEvent":{"action":"open_url","value":"https://google.com"}},{"text":"\n"},{"text":"Have Fun!"}]"
有没有办法封装我想要在 Minecraft 控制台中执行的命令,以便 screen 忽略所有引号,只在“ftb”屏幕上将整个命令发送到 Minecraft 控制台并执行?
该命令应在控制台中编写并执行:
tellraw @p ["",{"text":"This is a text!","bold":true,"color":"gold"},{"text":"\n"},{"text":"More text to be seen here!"},{"text":"\n"},{"text":"HAVE SOME TEXT IN UR FACE!","color":"green","clickEvent":{"action":"open_url","value":"https://google.com"}},{"text":"\n"},{"text":"Have Fun!"}]
答案1
这是一个外壳,不是一个screen
东西。您需要将整个内容放在单引号中。单引号中唯一的特殊字符是单引号(它结束引号)。
因此,这句话应该
say_this 'message'
例如
say_this 'tellraw @p ["",{"text":"This is a text!","bold":true,"color":"gold"},{"text":"\n"},{"text":"More text to be seen here!"},{"text":"\n"},{"text":"HAVE SOME TEXT IN UR FACE!","color":"green","clickEvent":{"action":"open_url","value":"https://google.com"}},{"text":"\n"},{"text":"Have Fun!"}]'