我試圖回答這個問題的建議:Test whether a glob has any matches in bash測試一個水珠是否在bash任何匹配 - 與變量
if test -n "$(find . -maxdepth 1 -name 'glob*' -print -quit)"
then
echo found
else
echo not found
fi
不過,我與變量的腳本這樣做。
#!/bin/sh
directory=~/nd
glob="*12*.idx"
cd $directory
if test -n "$(find . -maxdepth 1 -name \"$glob\" -print -quit)"
then
echo found
else
echo not found
fi
運行腳本給我:
not found
但在運行命令自己
find . -maxdepth 1 -name "*12*.idx" -print -quit
給我一個結果
./notes_archive_2012.idx
這是一個引用的問題?
非常好,謝謝。 :) –