Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 在Bash中同时循环文件中的行和目录中的文件_Linux_Bash_File_Loops - Fatal编程技术网

Linux 在Bash中同时循环文件中的行和目录中的文件

Linux 在Bash中同时循环文件中的行和目录中的文件,linux,bash,file,loops,Linux,Bash,File,Loops,我有一个目录中的文件和一个包含该目录中每个文件信息的文件。在文件上循环时,我需要有关当前正在处理的文件的信息。文件中的信息按与文件本身相同的顺序列出 我不能用Python或其他语言来实现这一点,因为我不能假设这些语言安装在目标机器上。我有Bash版本3.2。我知道Bash版本4可以使用关联数组,但我不能保证安装了这个版本 目前,我需要逐行读取文件: #FILE is the path to the informations file while read line do #do some

我有一个目录中的文件和一个包含该目录中每个文件信息的文件。在文件上循环时,我需要有关当前正在处理的文件的信息。文件中的信息按与文件本身相同的顺序列出

我不能用Python或其他语言来实现这一点,因为我不能假设这些语言安装在目标机器上。我有Bash版本3.2。我知道Bash版本4可以使用关联数组,但我不能保证安装了这个版本

目前,我需要逐行读取文件:

#FILE is the path to the informations file
while read line
do
    #do something with $line
done < $FILE

如何同时执行这些迭代?

在读取文件时不要使用
,只需读取
for
循环中的一行即可

for instance in "/path/to/files"/*
do
    read line
    # do something with $line and $instance
done < "$FILE"
例如在“/path/to/files”中/*
做
读线
#使用$line和$instance执行某些操作
完成<“$FILE”
for instance in "/path/to/files"/*
do
    read line
    # do something with $line and $instance
done < "$FILE"