我正在处理一个指定工具为 AWK 的任务。
任务是列出以下文件:
- 今天修改(脚本运行的同一天)
- 大小为 1 MB 或更小(大小 <= 1048576 字节)
- 用户的输入是指示从哪里开始搜索。
- 递归搜索文件。
脚本:
#!/bin/bash
#User's input target for search of files.
target="$1"
#Absolute path of target.
ap="$(realpath $target)"
echo "Start search in: $ap/*"
#Today's date (yyyy-mm-dd).
today="$(date '+%x')"
#File(s) modified today.
filemod="$(find $target -newermt $today)"
#Loop through files modified today.
for fm in $filemod
do
#Print name and size of file if no larger than 1 MiB.
ls -l $fm | awk '{if($5<=1048576) print $5"\t"$9}'
done
我的问题是for循环不介意文件的大小!
每个变量都会得到它的预期值。AWK 在 for 循环之外做它应该做的事情。我已经尝试使用引号无济于事。
谁能告诉我出了什么问题?
我感谢任何反馈,谢谢。
更新:我通过明确搜索文件解决了这个问题:
filemod="$(find $target -type f -newermt $today)"
这怎么重要?