我想自动安装一个Youtube内置的SDK。它提供了一个用于安装的shell脚本,但shell脚本需要用户输入,我想自动化。我尝试将以下内容添加到现有的shell脚本中,以自动安装SDK:
...
echo "built SDK, install SDK"
/usr/bin/expect -c '
spawn /path/to/SDK/install/script.sh
expect "Enter target directory for SDK (default: /opt/poky/3.1.5): \r"
send -- "\r"
expect "You are about to install the SDK to "/opt/poky/3.1.5". Proceed [Y/n]? \r"
send -- "\r"
'
/bin/bash
但这是我运行时得到的结果:
Poky (Yocto Project Reference Distro) SDK installer version 3.1.5
=================================================================
Enter target directory for SDK (default: /opt/poky/3.1.5): extra characters after close-quote
while executing
"expect "You are about to install the SDK to "/"
$
我不知道额外的字符错误来自哪里,有人能帮忙吗?
1条答案
按热度按时间yzxexxkh1#
你已经在一个双引号字符串中放入了双引号:
你得躲开他们
此外,Tcl/expect中的
[brackets]
是命令替换语法,因此一旦双引号问题得到解决,您可能会看到invalid command name "Y/n"
正确的解决方案是使用Tcl的非插值引用机制:牙套
参见http://www.tcl-lang.org/man/tcl8.6/TclCmd/Tcl.htm了解Tcl语法规则。