bash - Why is a file tested with -r not readable by cat? -
In this I have a cron job with two lines:
LOCK = / var / run / dns-check ... if [! -r "$ LOCK" - "$ ADDR_NOW"! = "$ (Cat $ LOCK)"]; Then This is the only use of cat in the script. Today I received the following error from the cron: cat: / var / run / Dns-check: there is no such file or directory I wonder what's happened here.
I am checking the file with -r so that it is legible and not the result. This means that if the file is not readable, the check is successful. Evaluation can stop here because the expression is already true. cat will not be called. Otherwise, the -o status is evaluated, which means if the file is executed, cat is executed. Why the cat reports the error, that the file can not be read, although test -r is detected that it is readable?
Using conditional form does not evaluate the short circuit instead, instead, try:
[! -r "$ LOCK"] || ["$ ADDR_NOW"! = "$ (Cat $ logical)"] Then the second check will only be if first failed.
Comments
Post a Comment