bash - 运行 gist.github.com 中的预期脚本

标签 bash expect gist

我知道我可以使用以下命令运行 gist.github.com 中的 bash 脚本:

bash -c "$(curl -fsSL https://raw.github.com/gist/5126919)" <arg0> <arg1>

我如何为 expect 脚本做同样的事情?

我这里有一个例子:

https://gist.github.com/simkimsia/5126919

#!/usr/bin/expect -f

set CHANGESHELL_FOR_USER [lindex $argv 0];
set PASSWORD_OF_USER [lindex $argv 1];

########################################
## switch to another user
## read this http://stackoverflow.com/a/1988255/80353
########################################
sudo -u $CHANGESHELL_FOR_USER -H sh -c "chsh -s /bin/bash" 

expect "*?assword:*" {send -- "$PASSWORD_OF_USER\r";}
expect eof

我的目的是为特定用户进行 chsh。

最佳答案

Bash 和 ksh 支持进程替换,因此您可以这样尝试:

expect <(curl ...) arg1 arg2 ...

我唯一能想到的问题是$argv0的值不是我们通常所期望的。您可以考虑在脚本中对其进行硬编码。

关于bash - 运行 gist.github.com 中的预期脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15318789/

相关文章:

jekyll - 运行 jekyll 服务器时关于 gist 的 <noscript> 标签的警告

r - 在 R 中使用 bash 获取行号

bash - 查找 ISO-8859-1 编码的文件?

Expect - expect_user 和 expect 的超时时间不同?

linux - 将 'sed' 到 'spawn' 执行到预期脚本中

git - 如何在github中创建一个返回json数据的 Gist

bash - 为 Suricata 创建 Bash 初始化脚本

arrays - json 响应的 Bash 脚本条件

linux - SFTP 手动命令成功但脚本在 1% 或 2% 处失败

git - 推送到 github gist 失败