LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Check whether a .zip exist or not (https://www.linuxquestions.org/questions/linux-newbie-8/check-whether-a-zip-exist-or-not-938724/)

xombboxer 04-08-2012 05:58 AM

Check whether a .zip exist or not
 
I am trying to check whether the file classes.zip is present or not using below line.
it seems its not able to check it. it says file does not exist, even though the file is present

Code:

if [ ! -f ${cacheFloc}/classes.zip ]
any help ?

engr04 04-08-2012 10:43 AM

Code:

if [ ! -f ${cacheFloc}/classes.zip ]
Is true if the file is not found

Code:

if [ ! -f ${cacheFloc}/classes.zip ]
Is true if the file is found

Example:

Code:

FILENAME=classes.zip

if [ -f $FILENAME ]; then
        echo $FILENAME found
else
        echo $FILENAME missing
fi

I have an embedded board where the '-f' option is not available. Here's an alternate way:

Code:

FILENAME=classes.zip

if [ `ls $FILENAME` ]; then
        echo $FILENAME found
else
        echo $FILENAME missing
fi


grail 04-08-2012 10:57 AM

Are you sure 'cacheFloc' has the correct value in it?

i92guboj 04-08-2012 12:17 PM

There's nothing wrong in that line but it depends in the context. As someone said you should check the contents of that var. Also, if you couldn't use -f I'd rather use 'stat' than 'ls'.


All times are GMT -5. The time now is 03:59 AM.