This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

bash programming: testing for empty string


Hi,

I'm trying to find the time of a file by doing this.

filetime=`ls -l --time-style=+%a:%H:%M /tmp/1.txt | awk '{print $6}'`

if [ -z "$filetime"]; then
 echo "File does not exist"
else
 echo "Time file: $filetime"
fi

However, when the file does not exist and filetime returns an empty
string, it does not evaluate [ -z "$filetime" ] to true
I have also tried the reverse which is

if [ -n "$filetime"]; then
 echo "Time file: $filetime"
else
 echo "File does not exist"
fi

but I still get the same results.

What does $filetime evaluate to when the command exits with an error?

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]