这个循环将显示我想要做的事情,但是如果我删除echo
从中,它实际上不会删除任何内容:
history | grep ":[0-5][0-9] ls *$" | cut -c1-5 |
while read id; do
echo history -d $id
done
我添加了缩进以使其更具可读性,但我从命令行将其作为一行运行。
I have HISTTIMEFORMAT
设置以便 grep 找到后面跟着的秒数ls
后跟任意数量的空格。本质上,它是在历史中发现任何只是一个ls
.
这是使用bash 4.3.11
on Ubuntu 14.04.3 LTS
history -d
从内存历史记录中删除一个条目,并且您正在管道引发的子 shell 中运行它。这意味着您要从子 shell 的历史记录中删除历史记录条目,而不是当前 shell 的历史记录。
使用进程替换来填充循环:
while read id; do
history -d "$id"
done < <(history | grep ":[0-5][0-9] ls *$" | cut -c1-5)
或者,如果您的版本bash
足够新,使用lastpipe
选项以确保您的while
循环在当前 shell 中执行。
shopt -s lastpipe
history | grep ":[0-5][0-9] ls *$" | cut -c1-5 |
while read id; do
echo history -d $id
done
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)