我對如何引用引號感到困惑

我對如何引用引號感到困惑

嗨,我對 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!"}]'

相關內容