加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

检查bash中是否存在git branch:奇怪的插值行为

发布时间:2020-12-15 22:07:49 所属栏目:安全 来源:网络整理
导读:我正在尝试查看 shell脚本中是否存在某个分支. 但是,git-branch似乎在插值时修改其输出. (我不知道这里的确切现象或术语) 例如,我正在尝试获取分支数组: $git branch develop* master$branches=`git branch`$echo $branchesdevelop compiler.sh HOSTNAME in
我正在尝试查看 shell脚本中是否存在某个分支.

但是,git-branch似乎在插值时修改其输出. (我不知道这里的确切现象或术语)

例如,我正在尝试获取分支数组:

$git branch
  develop
* master

$branches=`git branch`
$echo $branches
develop compiler.sh HOSTNAME index.html master

$echo `git branch`
develop compiler.sh HOSTNAME index.html master

一种ls文件似乎正在阻碍.怎么会?这是Bash吗? Git的?我糊涂了.

解决方法

git branch的输出包含*字符,表示您当前的分支:

$git branch
develop
*  master

在shell中运行echo *将打印工作目录的glob:

compiler.sh HOSTNAME index.html

因此,您的原始问题就出现了,因为在扩展之后,您实际上正在运行echo develop * master.

为了避免这种目录循环行为,你可以在echo期间强引用分支:

$branches=`git branch`
$echo "$branches"
develop
*  master

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读