LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2002, 03:19 PM   #1
The Grepper
LQ Newbie
 
Registered: Mar 2002
Posts: 9

Rep: Reputation: 0
Using a test


Hello, I want to test to see if a file is empty so its file is a size of 0.

im pretty sure its test -s filename, i have to look at the man pages to make sure, but thats not my prob. How would I be able to put test -s file, in an if statement so that if the answer is true, then do something. Ive tried to compare its result to an int, and other means, I just cant figure it out

Thanks a bunch

 
Old 04-04-2002, 03:49 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Code:
if [ -f filename ]
then
  if ! [ -s filename ]
  then
  go make a nice big tasty cake
  fi
fi
 
Old 04-04-2002, 04:36 PM   #3
The Grepper
LQ Newbie
 
Registered: Mar 2002
Posts: 9

Original Poster
Rep: Reputation: 0
but in order to do that I have to use the test

I meant something along the line of

if [ test -s filename -eq 0 ]
that doesnt work

thanks again
 
Old 04-04-2002, 04:41 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
[ IS test. it's just an attempt to make it look more like a normal language. try it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FC4 Test 1 CD Test failes every DISC Jimbo99 Linux - Software 1 03-18-2005 03:16 PM
test please tommytomato General 6 08-31-2004 06:41 AM
test eggCover Programming 1 07-26-2004 07:21 AM
Test Chiabert Linux - Newbie 5 10-02-2003 03:34 PM
test orange400 General 12 04-15-2003 06:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration