c - 如何编写缩进当前目录中所有文件 C/C++ 文件的 shell 脚本?

标签 c bash indentation

我正在尝试对当前目录中的所有文件运行 indent -kr -i8。作为一名 C 程序员,我想到的想法是 fork 等于文件数量的进程,并在它们上运行 exec。但我知道可以使用 shell 脚本简化事情。感谢任何形式的帮助。

最佳答案

你不仅可以:

indent -kr -i8 *.c

你提到了 fork 进程,所以如果你想同时进行:

for f in *.c
do
   indent -kr -i8 $f &
done

但是如果你有一大堆文件,那会浪费 cpu。所以分批:

limit=10
for f in *.c
do
   indent -kr -i8 $f &
   (( count = count + 1 ))

   if [[ $count -eq $limit ]] then
      wait
      count=0
   fi
done

关于c - 如何编写缩进当前目录中所有文件 C/C++ 文件的 shell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9839286/

相关文章:

c - C 是否标准化了链接器符号命名?

c - 枚举用法和运算符错误不匹配

linux - 以特定方式启动终端?

bash 循环跳过注释行

c - Gnu Emacs 缩进我的 typedef

c - C 中的运算符 : not greater and equal to.

c - strtok() 段错误

bash - 如何在 Bash 或 grep 或批处理中删除 HTML 文件的所有链接并将它们存储在文本文件中

python - python中简单while循环的问题(缩进)

lisp - Geany 作为 CommonLisp IDE