Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.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
Bash 从while循环内部获取变量_Bash_Variables_Pipe - Fatal编程技术网

Bash 从while循环内部获取变量

Bash 从while循环内部获取变量,bash,variables,pipe,Bash,Variables,Pipe,我有一个scritp,它收集关于文件子目录的信息。我正在检查文件创建之间的时间是否一致 last=0 LOGCHECK="YES" ls -l /dir/*.log | gawk '{print $8}' | sed s/:/*60+/g | bc | while read fname do current=$fname if [ $last = 0 ]; then last=$cur

我有一个scritp,它收集关于文件子目录的信息。我正在检查文件创建之间的时间是否一致

last=0
LOGCHECK="YES"
ls -l /dir/*.log | gawk '{print $8}' | sed s/:/*60+/g | bc |
        while read fname
        do
            current=$fname
            if [ $last = 0 ]; then
                last=$current
            elif [ $((current - last)) -ne 1 ]; then
                echo "Time difference discrepancy: $((current - last)) minute(s) is not expected"
                LOGCHECK="NO"
                last=$current    
            else
                last=$current
            fi      
        done
仅当.log文件创建之间的时间间隔不是一分钟时才输出。我的问题是while循环中的$LOGCHECK在另一个子shell中,我相信它来自管道


有没有办法获取此变量信息?

这是
bash
脚本编写的常见情况。按如下方式重新构造循环:

while read fname
do
  # stuff
done < <(ls -l /dir/*.log | gawk '{print $8}' | sed s/:/*60+/g | bc)
读取fname时

做
#东西
完成<