我有一个“sites”文件夹,其中包含许多名为:
bu.my-url.com
dud.myurl.com
[must-be-indentical_string].myurl.com
- ETC
在每个站点文件夹上,我想检查是否/themes/amu_[must-be-indentical_string]
与站点文件夹名称相同
/sites/[must-be-indentical_string].myurl.com/themes/amu_[must-be-indentical_string]
会有这样的命令吗?
答案1
你可以这样做:
#! /bin/sh -
cd /path/to/sites || exit
ret=0
for file in */themes/amu_*; do
[ -e "$file" ] || continue
dir=${file%%/*}
theme=${file##*/amu_}
case $dir in
("$theme".*) ;; # OK
(*) printf>&2 '%s\n' "Mismatch: $file"
ret=1;;
esac
done
exit "$ret"
对于 GNU find
,另请参阅:
cd /path/to/sites &&
find . -mindepth 3 -maxdepth 3 -regextype posix-basic \
-path './*/themes/amu_*' \
! -regex '\./\(.*\)\..*/themes/amu_\1' \
-fprintf /dev/stderr 'Mismatch: %P\n'