将命令生成的每行作为脚本中的一行
我有一个简单的脚本:
#!/bin/bash
dates_and_PID=$(ps -eo lstart,pid)
echo ${dates_and_PID::24}
我希望每行都在第24个字符上切割。但是,它将变量dates_and_pid
视为一行,因此我只有生成的一行。而我希望每行将其切割。
我正在练习,但最终目标是让脚本从2020年11月11日星期一更改为11/11/20
。
I have this simple script :
#!/bin/bash
dates_and_PID=$(ps -eo lstart,pid)
echo ${dates_and_PID::24}
And I would like each line to be cut at the 24th character. Nevertheless, it considers the variable dates_and_PID
as a single line, so I only have one line that is generated. Whereas I would like it to be cut for each line.
I am practicing but the final goal would be to have the script change the dates from Mon Nov 11 2020
to 11/11/20
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要逐行迭代输入,而不是将所有内容读取为单个变量。这样的事情应该解决问题:
You need to iterate over the input line by line, instead of reading everything into a single variable. Something like this should do the trick:
您可以将stdout送到
时
循环:You can pipe stdout to
while
loop: