【问题标题】:git commands not working when ran from a script从脚本运行时 git 命令不起作用
【发布时间】:2015-10-12 05:05:14
【问题描述】:

我正在尝试从脚本运行以下命令:

eval $(ssh-agent -s)
ssh-add

它们背后的目的是避免在当前会话的剩余时间里被要求提供我的 git 密码。一个一个地输入命令就可以了,所以我把它们放在了这个脚本中:

#!/bin/bash 

eval $(ssh-agent -s)
ssh-add

运行它后,我得到了 git 的正确响应:

$ gitnopasskey.sh
Agent pid 4260
Enter passphrase for /u/.ssh/id_rsa:
Identity added: /u/.ssh/id_rsa (/u/.ssh/id_rsa)

但是每次我获取、拉取等时仍然提示我输入我的密钥。我复制了脚本中使用的命令并一一输入,以确保我输入的是相同的命令,但是结果是一样的 - 输入命令时有效,从脚本运行时无效。

【问题讨论】:

  • 脚本在自己的 shell 中运行。请尝试获取脚本:source gitnopasskey.sh。否则,所有环境变量在你的父 shell 中都不会被触及(就像脚本中的 cd 不会触及你父母的工作目录)
  • 成功了,谢谢!

标签: git bash shell git-bash


【解决方案1】:

脚本在它们自己的 shell 中运行。尝试采购脚本:

source gitnopasskey.sh

否则所有环境变量都不会在你的父 shell 中被触及(就像脚本中的 cd 不会触及你父母的工作目录)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-07
    • 2016-11-11
    • 1970-01-01
    • 2019-12-15
    • 2013-04-30
    • 2021-10-23
    • 2021-11-01
    • 2020-01-02
    相关资源
    最近更新 更多