git fetch someremote # the remote is on github.com, and using SSH
如果我从终端发出上述命令会成功,但是如果我把它放在bash脚本中,它将会失败,但是:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我希望这能给某些人一些线索,帮助找出它在bash脚本中失败的原因,但在终端上取得成功!有人有任何想法吗?
如果我使用SSH或HTTPS
,似乎也会发生同样的事情答案 0 :(得分:2)
您的环境变量可能存在问题。为什么不试试diff
呢?
$ echo "printenv | sort > /tmp/script.env" > /tmp/envtest.sh
$ bash /tmp/envtest.sh
$ printenv | sort > /tmp/term.env
$ diff /tmp/term.env /tmp/script.env
在我的终端,我得到:
76c76
< SHLVL=1
---
> SHLVL=2