0

我正在使用此解决方案https://stackoverflow.com/a/10341883/6400605使用预定义的 -name 变量从指定文件夹获取文件列表,但在提供目录参数时它不起作用。

#!/bin/bash
if [ -n "$1" ] && [ -f "$1" ] ; then snames=$(basename "$1") ; fi
if [ -n "$1" ] && [ -d "$1" ] ; then snames=( '\* address.txt' -o -name '\*.log' -o -name '\*.rtf' -o -name '\* @unit credentials.doc' ) ; fi
start="$(dirname "$1")";
find "${start}/" -type f \( -name "${snames[@]}" \) -print0 | xargs -r0 -n1 bash -c '
echo "$2"
# ....more commands below 
' _  \;

这在提供路径+文件名时有效,但在提供目录参数时无效。

4

0 回答 0