gpt4 book ai didi

bash - 我如何以编程方式测试以查看github是否具有我的ssh key ?

转载 作者:行者123 更新时间:2023-12-02 14:23:16 25 4
gpt4 key购买 nike

我敢肯定,bash的日子不好过。

我似乎无法在if语句中正确获取退出代码。

我在这里做错了什么?

echo "Testing to see if GitHub knows who $USER is"
$(ssh -T "git@github.com")
echo $? #just for debugging
# Github exit code of 1 indicates that we can connect and that they do not support shell access.
# exit code of 255 indicates a ssh error, in this case we assume an invalid key
if [ "$?" != "1" ]; then
echo "Add your SSH key to your Github account"
echo "* Log into GitHub.com with your Github username and password and visit https://github.com/settings/ssh"
echo "* Click Add SSH Key"
echo "* Paste in the following under 'Key':"
echo "$(cat ~/.ssh/id_rsa.pub)"
echo "Press Enter when done."
read
fi

最佳答案

echo $?本身返回0,因此更改了$?。取出您的调试语句。

您还不需要$周围的引号吗?或1个您的条件(无论哪种方式对我都有效)。

关于bash - 我如何以编程方式测试以查看github是否具有我的ssh key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20150268/

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