在shell脚本中缩进多行输出 [英] Indenting multi-line output in a shell script

查看:1122
本文介绍了在shell脚本中缩进多行输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ubuntu Amazon EC2框上更改当天消息(MOTD),以便在我输入SSH时显示我其中一个目录的git状态.

I'm trying to change the message of the day (MOTD) on my Ubuntu Amazon EC2 box so that it will display the git status of one of my directories when I SSH in.

所有默认MOTD文件的输出在每行的开头都有两个空格,因此看起来很缩进,但是因为我的git status输出跨越了几行,所以如果我做echo -n " "之前它只缩进第一行,线.

The output from all of the default MOTD files have two spaces at the start of each line so it looks nicely indented, but because my git status output spans several lines, if I do echo -n " " before it only indents the first line.

有什么主意可以让我缩进每一行吗?

Any idea how I can get it to indent every line?

推荐答案

将其放在sed处,以便在每行的开头插入2个空格.

Pipe it to sed to insert 2 spaces at the beginning of each line.

git status | sed 's/^/  /'

这篇关于在shell脚本中缩进多行输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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