如何使用 shell 脚本和期望回答运行时问题



当我这样做时

git push

我得到命令提示符,例如

Username for 'https://github.com':

然后我手动输入我的用户名,就像

Username for 'https://github.com': myusername

然后我按回车键,提示输入密码

Password for 'https://myusername@github.com':

我希望用户名是自动写入的,而不是一直手动输入。 我尝试了期望,但无法使用它

谁能帮我写一个shell脚本?拜托:(

好吧,这是一个非常小的脚本,可以做你想要的

#!/bin/expect
spawn git push origin master
expect "Username for 'https://github.com': "
send "MY_NAME_IN_GITHUB"
interact

这样,你只需输入你的密码。您可以将此脚本绑定到某个 git 命令,它可以接受额外的参数,以便更改您的分支。

但我建议您自己创建ssh密钥并使用它们。这是一个很棒的教程,如何做到这一点:)ssh_tutorial GH并将其连接到ssh

最新更新