Look for file ksh

烈酒焚心 提交于 2019-12-12 05:49:19

问题


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]

回答1:


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

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


来源:https://stackoverflow.com/questions/36753444/look-for-file-ksh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!