Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Expect中应该转义哪些字符,以及如何转义?_Bash_Expect - Fatal编程技术网

Bash Expect中应该转义哪些字符,以及如何转义?

Bash Expect中应该转义哪些字符,以及如何转义?,bash,expect,Bash,Expect,我正在使用expect自动化脚本。这是我的剧本: setup_multicraft=$(expect -c " set timeout 10 spawn ./setup.sh expect \"Run each Minecraft server under its own user? (Multicraft will create system users): \\\[y\\\]/n\" send \"y\r\" 以下是一些原始脚本供参考: Run each Minecraft serve

我正在使用expect自动化脚本。这是我的剧本:

setup_multicraft=$(expect -c "

set timeout 10
spawn ./setup.sh

expect \"Run each Minecraft server under its own user? (Multicraft will create system users): \\\[y\\\]/n\"
send \"y\r\"
以下是一些原始脚本供参考:

Run each Minecraft server under its own user? (Multicraft will create system users): [y]/n
Run Multicraft under this user: [minecraft]
User not found. Create user 'minecraft' on start of installation? [y]/n
我知道括号、斜线、有时点等字符需要转义才能正常工作。但是,我在角色上尝试了几种转义序列组合,每次都会出现以下错误:

invalid command name "y\"
    while executing
"y\\"
    invoked from within
"expect "Run each Minecraft server under its own user? (Multicraft will create system users): \\[y\\]/n""
spawn ./setup.sh

谢谢你的阅读

您在shell中用双引号字符串声明expect脚本的方式是您的主要痛苦来源。如果不依赖于插值外壳变量,则可以使用一个单引号:

setup_multicraft=$(expect <<'END_OF_EXPECT'

    set timeout 10
    spawn ./setup.sh

    expect {Run each Minecraft server under its own user? (Multicraft will create system users): [y]/n}
    send "y\r"

    # ...
END_OF_EXPECT
)

setup\u multicraft=$(如果我需要使用shell变量,我是否能够以某种方式将其转义为使用shell变量?