git - 缩进 Bash 脚本输出

标签 git bash scripting indentation

我正在尝试编写一个 bash 脚本,但我很难使输出看起来整洁有序。我可以退而求其次,只使用换行符,但我更希望输出易于阅读。例如,当我运行 git clone ... 时,我想首先回显“Cloning repository”,然后缩进 git 的输出。示例输出:

Cloning repository...
    Initialized empty Git repository in /root/client_scripts/jojo/.git/
    remote: Counting objects: 130, done.
    remote: Compressing objects: 100% (121/121), done.
    remote: Total 130 (delta 13), reused 113 (delta 6)
    Receiving objects: 100% (130/130), 176.07 KiB, done.
    Resolving deltas: 100% (13/13), done.

目前,它都是压缩的,没有缩进。有谁知道如何做到这一点?我尝试使用 sedawk 但它似乎没有显示任何输出,只是 Initialized empty Git repository in/root/client_scripts/jojo/.git/。如果有任何意见,我将不胜感激。

最佳答案

通过管道

sed "s/^/    /g"

这将用四个空格替换行开头的(零宽度) anchor ,有效地在行的开头添加四个空格。

(g 全局执行此操作;没有它,它只会执行一次,即执行第一行。)

关于git - 缩进 Bash 脚本输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1670577/

相关文章:

visual-studio - 编写 Visual Studio IDE 脚本

git - 在 Git p4 提交期间忽略 Git 提交

git - "unpack failed: error Missing commit"但存在提交

git - 如何在 git 子模块中更改 "commit"?

xml - 使用 xslt unix 将 xml 转换为简单文件

linux - bash 脚本中的“全局化”Bash 函数

bash - 使用 bash printf 包装列的正确方法

node.js - 删除未跟踪的文件

bash - Bash 中的逻辑或 (||) 后跟冒号

linux - 两个文件与 while .sh 的比较