I'm creating a backup function to copy all files with an specific extension extension.
files() returns '*' '+' './' when it has not found file results, so I'm trying to avoid the invalid cp [* | + | ./] /backup with an if but it only works for *.
function backupByExt {
# $1 = extension $2 = searchPaths $3 = backPath
ext=$1
sp=$2
bp=$3
files=( "$sp" + *."$ext" )
# printf 'Backing up %s files: %d\n' "$ext" "${#files[@]}"
# loop over all the files having the current extension
for f in "${files[@]}"
do
# printf 'File: %s bp: %s\n' "$f" "$bp"
if [ "$f" != "*" ] && [ "$f" != "+" ] && [ "$f" != "./" ]; then
cp "$f" "$bp"
fi
done
}
bash?