Test command in UNIX | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Test command in UNIX

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-08-2013
kmanivan82 kmanivan82 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 14 July 2014, 8:02 PM EDT
Location: Chennai, INDIA
Posts: 58
Thanks: 7
Thanked 0 Times in 0 Posts
Test command in UNIX

Hi Team,


Code:
-rwxr-xr-x    1 kmani00  system            9 Nov 08 03:29 tempfile.txt
-rwxrwxrwx    1 kmani00  devgrp            0 Nov 08 03:32 testfile.txt

by exec the following command, i did not get any output.

Code:
> test -s tempfile.txt
> a=`test -s tempfile.txt`
> echo $a

>

by exec the following command, i did not get any output.

Code:
> test -s testfile.txt
> b=`test -s testfile.txt`
> echo $b

>

Not sure how this command works. How can i test the condition.

Can anyone help me out?

Thanks
Krishna

Last edited by Scrutinizer; 11-08-2013 at 08:24 PM.. Reason: code tags
Sponsored Links
    #2  
Old 11-08-2013
greet_sed greet_sed is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 5 July 2014, 5:50 AM EDT
Posts: 124
Thanks: 20
Thanked 33 Times in 32 Posts

Code:
if [ -s inputfile.txt ]; then echo "size is greater than zero"; else echo "size is not zero"; fi

Sponsored Links
    #3  
Old 11-08-2013
Akshay Hegde's Avatar
Akshay Hegde Akshay Hegde is offline Forum Advisor  
Forum Advisor
 
Join Date: Nov 2012
Last Activity: 31 July 2014, 2:03 PM EDT
Location: Goa / Bangalore, India
Posts: 1,418
Thanks: 72
Thanked 440 Times in 401 Posts
Try something like this...codetag please

if file exists and its size is greater than zero then print 0 else print 1

Code:
test -s file && echo "$? True" || echo "$? False"

    #4  
Old 11-08-2013
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 30 July 2014, 5:10 AM EDT
Location: /dev/ph
Posts: 4,773
Thanks: 59
Thanked 423 Times in 392 Posts
The test command does not output anything. It returns either TRUE or FALSE via its exit code, with 0 being TRUE and 1 being FALSE.
Sponsored Links
    #5  
Old 11-09-2013
kmanivan82 kmanivan82 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 14 July 2014, 8:02 PM EDT
Location: Chennai, INDIA
Posts: 58
Thanks: 7
Thanked 0 Times in 0 Posts
Thank you all for your reply.

Thank you so much.

Krishna
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
TEST Command Aswex Shell Programming and Scripting 12 02-24-2011 10:32 AM
How to check weather a string is like test* or test* ot *test* in if condition johnjerome Shell Programming and Scripting 5 02-18-2010 05:38 AM
Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d Max89 Shell Programming and Scripting 1 11-25-2009 01:08 PM
Unix grep/test command netmaster UNIX for Dummies Questions & Answers 4 05-08-2009 02:05 AM
the TEST command marwan UNIX for Dummies Questions & Answers 2 04-23-2007 06:51 PM



All times are GMT -4. The time now is 09:52 AM.