English 中文(简体)
使用文件名中的通配符在 unix 中查找文件
原标题:finding a file in unix using wildcards in file name

我在一个有名称模式的文件夹中, 仅有少量文件, 其中一个区域是变量 。

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 而非查找也行不通:

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

fi

我在这里做错什么了?

谢谢你看书!

最佳回答

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

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

问题回答
for i in file1.abc.*.xyz ; do
    # use $i here ...
done




相关问题
Generate assembler code from C file in linux

I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I m getting errors. I m trying to build an ...

Function to create the array by reading the file

I am creating scripts which will store the contents of pipe delimited file. Each column is stored in a separate array. I then read the information from the arrays and process it. There are 20 pipe ...

Compare characters at the end of the string C++

This program supposed to find command line arguments entered on Unix which ends with “.exe”. For some reason it doesn t work. Here is the code: int main( int argc, char* argv[] ) { for ( int ...

Batch Job Dependencies Using Open Source/Free Software

I run a large data warehouse plant where we have a lot of nightly jobs running concerruently however many have dependencies on a extract or data load process before they start. Currently we use an ...

Writing application for both Unix and Windows

I ll write a program for Interactive UNIX (http://en.wikipedia.org/wiki/INTERACTIVE_UNIX). But in a year it will be ported to Windows. I ll write it in ANSI C and/or SH-script. When it runs on Windows ...

Development Environment in Windows [closed]

What are your recommendations for setting up a development environment in Windows, especially when not using an IDE. I am attempting to familiarize myself with Windows, and I feel a bit lost. What ...

热门标签