Bash 从while循环内部获取变量
我有一个scritp,它收集关于文件子目录的信息。我正在检查文件创建之间的时间是否一致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
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时
做
#东西
完成<