我有一个文本文件,每行包含一个单词。
我需要 bash 中的一个循环来读取每一行,然后在每次读取一行时执行一个命令,使用该行的输入作为命令的一部分。
我只是不确定在 bash 中执行此操作的正确语法。如果有人可以提供帮助,那就太好了。我需要使用从测试文件中获得的行作为参数来调用另一个函数。当文本文件中没有更多行时,循环应该停止。
伪代码:
Read testfile.txt.
For each in testfile.txt
{
some_function linefromtestfile
}
怎么样:
while read line
do
echo $line
// or some_function "$line"
done < testfile.txt
作为替代方案,使用文件描述符(在这种情况下为#4):
file='testfile.txt'
exec 4<$file
while read -r -u4 t ; do
echo "$t"
done
不要使用cat!在循环cat中几乎总是错误的,即
cat testfile.txt | while read -r line
do
# do something with "$line" here
done
人们可能会开始向你扔UUoCA。
while read line
do
nikto -Tuning x 1 6 -h $line -Format html -o NiktoSubdomainScans.html
done < testfile.txt
从 cat 方法更改后,尝试使用此方法自动对域列表进行 nikto 扫描。仍然只是阅读第一行并忽略其他所有内容。