Unix check file exist or not
Possible duplicate of How do I tell if a regular file does not exist in Bash? You must set one or more whitespace between opening square bracket "[" and option "-e" same as between filename and closing square bracket "]" — Konstantin Yaniv. Related: Why do we need a space around square brackets in Bash if. Add a comment. Active Oldest Votes. You're missing a required space between the bracket and -e :!
Improve this answer. The script seems to work now. The main difference here is the fact that you are using "bash" scripting instead of "shell" scripting. Notice that the first line that you have added was! Because sh doesn't recognize that argument "-e" — Nick Cuevas. Here is an alternative method using ls : ls x. Philip Kirkbride Philip Kirkbride This code means: "if ls is successful, there is such file, otherwise, there is none".
If ls failed, it does not mean that file is missing. It might be some other error. For example, create file in directory owned by root and try to do ls under regular user. Check Word if exist on file or not. Steven 2 Replies. I can use access under Window MFC. Steven 1 Reply. RedHat Commands. OpenSolaris Commands. Linux Commands. SunOS Commands. FreeBSD Commands.
Full Man Repository. Advanced Search. If they are required , then it seems to me your script should fail if any of them is missing, not if all of them are missing. Add a comment. Active Oldest Votes. Improve this answer. I'm not able to check it out in ksh on AIX. The Overflow Blog. Podcast Making Agile work for data science. Ant: mkdir -p : create all the necessary directories, without complaining if one already exists.
One could even get rid of the if To start with, shell script is not bash script , so let's make your code more general:! James K. Lowden James K. Lowden 1, 10 10 silver badges 14 14 bronze badges. DopeGhoti DopeGhoti LSerni LSerni 3, 11 11 silver badges 18 18 bronze badges.
You're not checking if the file exists — PiedPiper. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.
0コメント