问题
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