寻找档案ksh [英] Look for file ksh

查看:78
本文介绍了寻找档案ksh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习unix.我想设置一种文件监视程序,该文件监视程序查找文件并返回文件名,以便我可以将它们从源移动到处理文件夹以进行处理.它回显了找到的文件",我只是不知道如何捕获文件名.

I am trying to learn unix. I wanted to set up a sort of file watcher that looks for files and returns the file names so i can move them from source to processing folder to process. It echos File Found I just cannot figure out how to capture the file name.

#determines if file exists
if  [ -f  * ]; then 
    echo "File found"
else 
    echo "File not Found"
fi  

# returns file to array
#Needs name still
NewFiles[0] = 

#output what what found in 0 index
echo "Found File"
echo NewFiles[0]

推荐答案

假设文件没有奇特的名称(嵌入式空格或类似名称),则可以使用该方法:

Assuming the files have no fancy names (embedded spaces or similar), you might use that approach:

set -- *
[ $# -gt 0 ] && {
    echo Found file
    echo $1
}

这篇关于寻找档案ksh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆