Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Test command in UNIX

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-08-2013
kmanivan82 kmanivan82 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 20 March 2015, 7:00 PM EDT
Location: Chennai, INDIA
Posts: 73
Thanks: 14
Thanked 1 Time in 1 Post
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 Unix and Linux 11-08-2013
greet_sed greet_sed is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 6 April 2015, 4:47 PM 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 Unix and Linux 11-08-2013
Akshay Hegde's Unix or Linux Image
Akshay Hegde Akshay Hegde is offline Forum Advisor  
Forum Advisor
 
Join Date: Nov 2012
Last Activity: 22 May 2015, 12:12 AM EDT
Location: Goa / Bangalore, India
Posts: 1,710
Thanks: 84
Thanked 575 Times in 524 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 Unix and Linux 11-08-2013
fpmurphy's Unix or Linux Image
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 23 May 2015, 8:47 PM EDT
Location: /dev/ph
Posts: 4,923
Thanks: 68
Thanked 455 Times in 422 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 Unix and Linux 11-09-2013
kmanivan82 kmanivan82 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 20 March 2015, 7:00 PM EDT
Location: Chennai, INDIA
Posts: 73
Thanks: 14
Thanked 1 Time in 1 Post
Thank you all for your reply.

Thank you so much.

Krishna
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 05:24 AM.