bash 5-从被调用函数继续循环

bash 5-从被调用函数继续循环,bash,Bash,我最近刚从bash4.2迁移到5.0,不明白为什么这个函数在while循环中调用时不跳过 alreadyInQueue () { # skip files if already in queue for task in "$HOME/.encode_queue/queue/"* do # Break if no task found [[ -f "$task" ]] || break # Sed line two from task file

我最近刚从bash4.2迁移到5.0,不明白为什么这个函数在while循环中调用时不跳过

alreadyInQueue () 
{
  # skip files if already in queue
  for task in "$HOME/.encode_queue/queue/"*
  do

      # Break if no task found
      [[ -f "$task" ]] || break

      # Sed line two from task file in queue (/dev/null error on empty queue)
      line=$( sed '2q;d' "$task" 2>/dev/null )

      # Store initial IFS
      OLD_IFS=$IFS

      # Extract tag and file from line
      IFS='|' read nothing tag file <<< "$line"

      # Restore IFS
      IFS=$OLD_IFS

      # Skip files already in queue with same preset (tag)
      if [[ "$tag" == "${tag_prst[x]}" && "$file" == "$1" ]]; then

      # Silent skip $2 argument: echo only if $2 = 1 
      [[ "$2" -eq "1" ]] && echo -e "\n** INFO ** Encode Queue, skip file already in queue:\n$i"

      # Continue n
      continue 2

      fi
  done 
}
脚本回显:**信息**编码队列,跳过队列中已存在的文件:。。。 但不会继续到下一个文件迭代

当在函数调用中未执行continue时,它会工作

        # Find specified files
        find "$job_path" "${args_files[@]}" | sort | while read -r i
        do

        # Extracts var from $i
        fileSub

        # Skip files already in queue
        #alreadyInQueue "$i" "1"

        # skip files if already in queue waiting to be encoded
        for task in "$HOME/.encode_queue/queue/"*
        do

            # Break if no task found
            [[ -f "$task" ]] || break

            # Sed line two from task file in queue (/dev/null error on empty queue)
            line=$( sed '2q;d' "$task" 2>/dev/null )

            # Store initial IFS
            OLD_IFS=$IFS

            # Extract tag and file from line
            IFS='|' read nothing tag file <<< "$line"

            # Restore IFS
            IFS=$OLD_IFS

            # Skip files already in queue with same preset (tag)
            if [[ "$tag" == "${tag_prst[x]}" && "$file" == "$i" ]]; then

            # Silent skip $2 argument: echo only if $2 = 1 
            [[ "1" -eq "1" ]] && echo -e "\n** INFO ** Encode Queue, skip file already in queue:\n$i"

            # Continue n
            continue 2

            fi
        done

        echo "i should be skipped"

        done

#查找指定的文件
读取-r i时查找“$job_path”“${args_files[@]}”|排序|
做
#从$i中提取var
文件订阅
#跳过队列中已存在的文件
#已准备就绪队列“$i”1
#如果已在队列中等待编码,则跳过文件
对于“$HOME/.encode_queue/queue/”中的任务*
做
#如果未找到任务,则中断
[[-f“$task”]| |中断
#Sed队列中任务文件的第二行(/dev/null错误位于空队列上)
行=$(sed'2q;d'$task“2>/dev/null)
#存储初始IFS
OLD_IFS=$IFS
#从行中提取标记和文件

IFS=“|”不读取标记文件这是在
bash
4.4中修复的错误:

xx。修复了一个允许从shell执行'break'或'continue'的错误 函数影响在函数外部运行的循环


非常感谢。请问我该怎么做才对?作为一名业余爱好者,我正在编写代码,希望通过
return 1
alreadyInQueue“$i”“1”| | continue
再次感谢您为我指明了正确的方向。正确:退出状态是函数与其调用者通信的正确方式(也是一种很好的方式)。
        # Find specified files
        find "$job_path" "${args_files[@]}" | sort | while read -r i
        do

        # Extracts var from $i
        fileSub

        # Skip files already in queue
        #alreadyInQueue "$i" "1"

        # skip files if already in queue waiting to be encoded
        for task in "$HOME/.encode_queue/queue/"*
        do

            # Break if no task found
            [[ -f "$task" ]] || break

            # Sed line two from task file in queue (/dev/null error on empty queue)
            line=$( sed '2q;d' "$task" 2>/dev/null )

            # Store initial IFS
            OLD_IFS=$IFS

            # Extract tag and file from line
            IFS='|' read nothing tag file <<< "$line"

            # Restore IFS
            IFS=$OLD_IFS

            # Skip files already in queue with same preset (tag)
            if [[ "$tag" == "${tag_prst[x]}" && "$file" == "$i" ]]; then

            # Silent skip $2 argument: echo only if $2 = 1 
            [[ "1" -eq "1" ]] && echo -e "\n** INFO ** Encode Queue, skip file already in queue:\n$i"

            # Continue n
            continue 2

            fi
        done

        echo "i should be skipped"

        done