如何从历史中复制命令?

Léo*_* 준영 0 awk history sed

我尝试从历史中复制命令.如何复制第510个命令?请看下面的数据.我的赌注是:

history | grep 510 | sed '1q;d' | awk '{print $2-$10}' | pbcopy
Run Code Online (Sandbox Code Playgroud)

但输出是0.我无法理解原因.命令有什么问题?

  505  find . -perm=750 -print0 | xargs -0 chmod 750
  506  find . --perm=750 -print0 | xargs -0 chmod 750
  507  find . -perm=750 -print0 | xargs -0 chmod 750
  508  find . -perm=750 -print0 | xargs -0 chmod 750
  510  find . -perm 750 -print0 | xargs -0 chmod 750
  512  history | grep perm 750 -print0 | pbcopy
Run Code Online (Sandbox Code Playgroud)

sth*_*sth 5

如果你正在使用bash:

echo "!510" | pbcopy
Run Code Online (Sandbox Code Playgroud)

(另请参阅bash手册中的"历史扩展" )