0

我在具有名称模式的文件夹中有几个文件,其中一个部分是可变的。

file1.abc.12.xyz
file2.abc.14.xyz
file3.abc.98.xyz

所以上面三个文件名中的第三部分(数字)每天都在变化。

现在,我有一个脚本可以对文件数据执行一些任务。但是,在工作之前,我想检查文件是否存在,然后执行任务:

if(file exist) then
     //do this
fi

我在数字部分使用通配符“*”编写了以下代码:

export mydir=/myprog/mydata

if[find $mydir/file1.abc.*.xyz]; then 
   # my tasks here

fi

但是,它不起作用并给出以下错误:

 [find: not found [No such file or directory]

使用 -f 而不是 find 也不起作用:

if[-f $mydir/file1.abc.*.xyz]; then
  # my tasks here

fi

我在这里做错了什么?我正在使用 korn shell。

谢谢阅读!

4

2 回答 2

0
for i in file1.abc.*.xyz ; do
    # use $i here ...
done
于 2012-05-22T06:50:23.257 回答
0

我没有在 unix 关键字之前使用空格...

例如,“if[-f”实际上应该是“if [-f”,括号前后有空格。

于 2012-05-30T08:30:39.523 回答