从git status bash输出创建字符串数组 [英] Create string array from git status bash output

查看:134
本文介绍了从git status bash输出创建字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建修改后的git文件的字符串数组,以便可以在bash程序中使用它们.样本输出:

I am trying to create a string array of my modified git files so I can use them in a bash program. Sample output:

On branch restructured
Your branch is up-to-date with 'origin/restructured'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified: path/to/file1 
    modified: path/to/file2

我正在尝试获取modified:之后的文本,但是从我发现的grep来看,它没有

I'm tryig to grab the text after modified: but from what I've found grep doesn't support new line so i'm at a loss how I could convert the raw output into something I could work with.

推荐答案

怎么样:

files=(git status | grep '^\s*modified:' | cut -f 2- -d :)

从内而外的阅读,即:

  • git状态传递给grep,这
  • 查找单行上带有modified:的行,然后
  • 在这些行上切掉结肠后的所有内容,然后最后
  • 将其放入分配给$files
  • 的数组中
  • Passes git status to grep, which
  • looks for lines with modified: on them singularly, then
  • cuts everything after the colon on those lines, then finally
  • puts that into an array assigned to $files

这篇关于从git status bash输出创建字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆