for循环中的“参数列表太长”

use*_*862 4 shell shell-script

我的 shell 脚本如下所示:

#!/bin/bash

for file in *.fasta
do

signalp $file > $file.txt

done
Run Code Online (Sandbox Code Playgroud)

在工作文件夹中,我有 18.000 个 .fasta 文件。我想通过signalp程序运行每个。我猜它文件夹中的文件太多,但我不知道如何调整我的代码。有什么帮助吗?

hee*_*ayl 5

您可以使用find

find . -maxdepth 1 -type f -exec sh -c 'signalp "$1" >"$1".txt' _ {} \;
Run Code Online (Sandbox Code Playgroud)
  • -maxdepth 1将仅在当前目录中find搜索文件 ( -type f)

  • sh -c 'signalp "$1" >"$1".txt'将对signalp找到的所有文件执行该命令,并将输出保存到添加.txt到原始文件名后命名的文件中。