![](/img/trans.png)
[英]Automatically capture output of last command into a variable using Bash?
[英]how to capture the 1st command output in terminal and to print that variable using the last command in the same line
实际输出为
$ grep -Hcw count copy_hb_script
copy_hb_script:5
我正在使用以下命令来获得预期的结果,但失败了
grep -Hcw count copy_hb_script | awk '{print $1}' |xargs ls -ld | awk '{print $8 " " $9 }'
下车是
03:49 copy_hb_script
缺少文件计数,是否有其他方法可以获取带有文件计数的时间戳,如下所示
03:49 copy_hb_script:5
您can avoid parsing ls output
而在bash中使用stat
命令获取详细的文件信息。
# 'stat -c' produces output as 2016-09-15 16:03:40.655456000 +0530
# Stripping off extra information after the '.' using string-manipulation
# Running the grep with the count together with the previous command
modDate=$(stat -c %y copy_hb_script); echo "${modDate%.*}" "$(grep -Hcw count copy_hb_script)"
产生输出为
016-09-15 16:03:40 copy_hb_script:5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.