www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/03/05/04:28:34

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <f253cf4b0803050127y292c130djce5ef5745099f7fb@mail.gmail.com>
Date: Wed, 5 Mar 2008 17:27:39 +0800
From: "bootleg86 bootleg86" <bootleg86 AT gmail DOT com>
To: cygwin AT cygwin DOT com
Subject: bash programming: testing for empty string
MIME-Version: 1.0
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019