2013-11-22 2 views
1

나는 bash와 함께 나쁜 하루를 보내고 있다고 확신한다.github에 ssh 키가 있는지 테스트하려면 어떻게 프로그래밍합니까?

if 문에서 종료 코드를 제대로 비교할 수없는 것 같습니다.

내가 뭘 잘못하고 있니?

echo "Testing to see if GitHub knows who $USER is" 
$(ssh -T "[email protected]") 
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 

답변

2

echo $?은 그 자체가 0을 반환하므로 $가 변경됩니다. 디버그 문을 꺼내십시오.

$ 주변에는 따옴표가 필요하지 않습니까? 또는 귀하의 조건부에 1 (어느 쪽이든 나를 위해 일했다.)

+0

고마워! 나는 그게 뭔가 간단하다는 것을 알았습니다. – hafichuk

관련 문제