两个 Shell 参数扩展一前一后不起作用 (Bash)

PHP*_*uru 0 bash

使用 Bash 4.4 我试图从当前目录获取文件列表,将它们放入一个数组中,然后使用 shell 参数扩展从数组中删除其路径中包含 /cache/ 和 /tmp/ 的文件。

这是我到目前为止所拥有的,但它不起作用。问题似乎是第二个字符串替换发生在第一个字符串替换将其结果存储到first_array 之前。因此,当第二次替换执行时,first_array 还没有值,导致 secondary_array 为空。目标是获取具有昨天日期时间戳且路径中不包含 /cache/ 或 /tmp/ 的文件列表。

#!/bin/bash

FIND="$(find . -type f -newermt $(date -d 'yesterday 13:00' '+%Y-%m-%d') ! -newermt $(date '+%Y-%m-%d'))"
readarray -t my_array <<<"$FIND"
first_array="${my_array[@]//*\/tmp\/*/}"
second_array="${first_array[@]//*\/cache\/*/}"
Run Code Online (Sandbox Code Playgroud)

Léa*_*ris 5

过滤掉 中不需要的路径find,并使用 find 的分隔输出填充数组null

readarray -d '' -t my_array < <(
  find . -type f \
    -not \( \
      -path '*/tmp/*' -o -path '*/cache/*' \
    \) \
    -newermt "$(date -d 'yesterday 13:00' '+%Y-%m-%d %H:%M:%S')" \
    -not -newermt "$(date '+%Y-%m-%d')" \
    -print0
)
Run Code Online (Sandbox Code Playgroud)