【问题标题】:How do I programatically test to see if github has my ssh key?如何以编程方式测试 github 是否有我的 ssh 密钥?
【发布时间】:2013-11-23 01:07:50
【问题描述】:

我确定我只是在 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

【问题讨论】:

    标签: bash github ssh


    【解决方案1】:

    echo $? 本身返回 0 并因此更改 $?。拿出你的调试语句。

    您也不需要在 $ 周围加上引号?或 1 在您的条件中(无论哪种方式都对我有用。)

    【讨论】:

    • 谢谢!我知道这很简单。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 2018-08-20
    • 2022-01-19
    • 2021-02-23
    • 2012-04-03
    • 2016-01-19
    • 1970-01-01
    相关资源
    最近更新 更多