从crontab运行脚本时,while循环在shell脚本中不工作
我正在尝试使用while循环逐行读取文件,如:从crontab运行脚本时,while循环在shell脚本中不工作,shell,while-loop,crontab,Shell,While Loop,Crontab,我正在尝试使用while循环逐行读取文件,如: while read Line; do echo Inside outer loop while read Line2; do ..... echo Inside inner loop ..... done < /absolute path of file/filename2 done < /absolute path of file/filena
while read Line; do
echo Inside outer loop
while read Line2; do
.....
echo Inside inner loop
.....
done < /absolute path of file/filename2
done < /absolute path of file/filename
读行时;做
外环路内回波
读第2行时;做
.....
内环回波
.....
完成
独立运行时,脚本工作正常。但当它从crontab运行时,它不会进入循环内部
请说明可能的原因 第二个while循环正在读取所有输入(除了“filename”的第一行)。您需要重定向到单独的文件描述符:
while IFS= read -r -u3 Line; do
echo Inside outer loop
while IFS= read -r -u4 Line2; do
.....
echo Inside inner loop
.....
done 4< "/absolute path of file/filename2"
done 3< "/absolute path of file/filename"
当IFS=read-r-u3行时;做
外环路内回波
而IFS=read-r-u4第2行;做
.....
内环回波
.....
完成4<“/文件的绝对路径/filename2”
完成3<“/文件的绝对路径/文件名”
- 使用
和IFS=
确保从文件中逐字读取该行李>read-r
和read-u3
使用特定fd3
- 如果实际路径有空间,则需要引用文件名