【问题标题】:How to get a Git repo url saved in a bash script to a variable如何将 bash 脚本中保存的 Git repo url 保存到变量中
【发布时间】:2015-01-02 03:57:18
【问题描述】:

在运行 postinstall 到 npm install 的 bash 脚本中,我想获取名为 base 的特定 repo 的 Github 远程 URL。但是,当它运行时,提取的值是“git”,而不是我的 git 存储库的 URL。您将如何捕获从该命令返回的 URL?

#!/bin/bash
...
remoteBackup=git config --get remote.base.url
...

【问题讨论】:

    标签: node.js git bash github


    【解决方案1】:

    var=$(command that produces output) 不是var=value command

    后者在设置为value的环境中运行commandvar

    假设这是您在脚本中实际拥有的内容,而不是拼写错误。如果这是一个拼写错误并且让您返回git 而不是git@bitbucket,那么听起来您的配置搞砸了。

    【讨论】:

    • 嗨,谢谢,效果很好,我不知道您必须包装这样的命令才能分配它。抱歉,我会解决这个问题,然后输入我的 git 存储库 URL。
    猜你喜欢
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 2021-12-03
    • 1970-01-01
    • 2017-12-08
    • 2011-10-21
    相关资源
    最近更新 更多