gpt4 book ai didi

linux - 期望脚本返回 "missing close-bracket"

转载 作者:太空宇宙 更新时间:2023-11-04 10:30:53 25 4
gpt4 key购买 nike

我编写了一个 bash 脚本,它从 API 获取密码并使用“发送”来设置此密码

un=admin
pw=$(get_json_value_from_file "$rsm_res_file" "password")
echo $pw
export HISTIGNORE="expect*";
expect -c "
spawn ssh -o UserKnownHostsFile=$ap_known_hosts_file -p $PORT $un@localhost
expect "*ogin*"
send \"$un\r\"
expect "*assword*"
send \"$pw\r\"
interact"

它重新调整了以下异常:

  missing close-bracket
while executing "send \"f40T[2[6g%^TsMLv\r\"
interact"

我认为是特殊字符的问题。

最佳答案

您的密码包含一个具有特殊含义的[ 字符。 Tcl/Expect 中的 [...] 语法是命令替换,就像 `...`$(.. .)Bash 中。要获得文字 [,您必须使用 \[。对于您的场景,最简单的解决方案是使用环境变量将密码从 Bash 传递到 Expect。例如:

PASSWORD=$pw expect -c "
spawn ssh -o UserKnownHostsFile=$ap_known_hosts_file -p $PORT $un@localhost
expect "*ogin*"
send \"$un\r\"
expect "*assword*"
send \$env(PASSWORD)\r
interact"

export PASSWORD=$pw
expect -c "
spawn ssh -o UserKnownHostsFile=$ap_known_hosts_file -p $PORT $un@localhost
expect "*ogin*"
send \"$un\r\"
expect "*assword*"
send \$env(PASSWORD)\r
interact"

关于linux - 期望脚本返回 "missing close-bracket",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39994688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com