相关疑难解决方法(0)

为什么循环查找的输出是不好的做法?

这个问题的灵感来自

为什么使用 shell 循环处理文本被认为是不好的做法?

我看到这些结构

for file in `find . -type f -name ...`; do smth with ${file}; done
Run Code Online (Sandbox Code Playgroud)

for dir in $(find . -type d -name ...); do smth with ${dir}; done
Run Code Online (Sandbox Code Playgroud)

几乎每天都在这里使用,即使有些人花时间对这些帖子发表评论,解释为什么应该避免这种东西......
看到此类帖子的数量(以及有时这些评论被简单地忽略的事实)我想我还不如问一个问题:

为什么循环find的输出是不好的做法,为 返回的每个文件名/路径运行一个或多个命令的正确方法是find什么?

find filenames files for

193
推荐指数
4
解决办法
3万
查看次数

Bash:IF-THEN 语句中的“参数太多”

我正在尝试检查特定文件是否存在(但仅当存在时间少于 24 小时时),如果存在,则执行第二次检查以查看名称以“.control”结尾的文件是否存在。如果满足这两个条件,则创建电子邮件和日志条目。如果第一个文件存在但 .control 不存在,则创建一个不同的日志条目。如果不到 24 小时的文件不存在,则继续执行脚本的其余部分。

这是在 Solaris 和 Linux 上使用 Bash 从 cron 启动的 shell 脚本中。

if [ find "$MAINTENANCE_LOCK/testLOCK" -mtime -1 ]; then
    if [ -f "$PATH_TO_TRIGGER_FILES/*.control" ]; then
        test_log_msg "test_SYSTEM" $NOTICE "Valid Maintenance Lock file found, test actions blocked." "status"
        test_log_email " " " " " " "test Actions were blocked because an testLOCK file less than 24hrs old is in place." " "
    else
        test_log_msg "test_SYSTEM" $NOTICE "Valid Maintenance Lock file in place." "status"
        exit …
Run Code Online (Sandbox Code Playgroud)

bash shell-script

2
推荐指数
1
解决办法
1490
查看次数

标签 统计

bash ×1

filenames ×1

files ×1

find ×1

for ×1

shell-script ×1