为什么这个脚本会在 txt 文件的第一行循环?

1 bash io-redirection shell-script read

#!/bin/bash
usernameFile="/home/netadmin/username_list.txt"

logFile="/var/log/netvpn-mag-archive/netvpn-mag-20160"

  while read -r line < $usernameFile; do
    if [[ "$line" != " " ]]; then
            zgrep -w "$line" "$logFile"* >> grep_output.txt
    fi
  done < "$usernameFile"
Run Code Online (Sandbox Code Playgroud)

使用此脚本,我想针对用户名文件中的每个用户的日志文件进行 grep。目前,脚本一遍又一遍地遍历第一个用户名。我需要它在浏览日志文件目录中的所有文件后停止并移动到列表中的下一个名称。

Arc*_*mar 6

有两个地方可以输入“$usernameFile”:一个在全局循环中,另一个在 read 中。

while read -r line < $usernameFile; do

done < "$usernameFile"
Run Code Online (Sandbox Code Playgroud)

我认为你应该只在全局循环中输入它。(换句话说,只能在“完成”之后放置。)