We assume the current directory has a number of directories named D.userid, each of which contains submitted Java files. How to detect if there is D.userid present in a directory? What should be the code. I dont this mine is rite
#!/bin/bash
if [ -d "$D.*" ]
then
else
echo "no .java file(s) submitted"
exit
fi
done
Since you assume there are files, and only want to be informed that there are none, I think this is reasonable:
ls D.* > /dev/null # try to list the files. we don't need output
return=$? # save the return value of ls just in case
if [ $return -ne 0 ]; # compare it to 0 (success)
then
echo "No files."
fi
ls
returns 2 if the files are not found, so if you want you can use that directly. Of course, it doesn't check that they are directories, but it's just another way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.