假设该文件夹$folder
包含文件2012-01,...,2012-N1,2013-01,...,2013-N2
等。
我希望我的脚本要求一个自然数M
并且:
if the files 20M-* exist
then ask for other natural number M2 and
if the file 20M-M2 exists
then open it
else warning msg
由于文件变化很大,我的case
测试不是那么动态。
任何想法?谢谢。
答案1
我相信你可以更优雅地这样做......留给读者的练习。 :P
echo M?
read M
for f in 20"$M"-*
do
if [ -e "$f" ]
then
echo M2?
read M2
for f in 20"$M"-"$M2"
do
if [ -e "$f" ]
then
echo SUCCESS
cat "$f"
exit
fi
done
echo FAIL: There is no file for 20"$M"-"$M2"
exit 1
fi
echo FAIL: There is no file for 20"$M-*"
exit 1
done