unix 删除Zsh中的尾随空格:致命错误:堆内存不足

lbsnaicq  于 2023-01-05  发布在  Unix
关注(0)|答案(1)|浏览(150)

有人知道我为什么会得这种病以及如何预防吗?

#!/usr/bin/env zsh

setopt nullglob
setopt extendedglob

for file in **/*; do
  if file -b $file | grep -q "text"; then
    raw=$(<$file)

    # Remove trailing whitespace
    raw=${raw//[[:blank:]]##$'\n'/$'\n'}

    # Other stuff like removing CR+LF works fine
    # raw=${raw//$'\r'}

    echo $file
    printf "%s\n\n" $raw > $file
  fi
done
sy5wg1nm

sy5wg1nm1#

Fravadona用${raw//$'[ \t]##\n'/$'\n'}修好了,非常感谢!

相关问题