Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Test command in UNIX

Shell Programming and Scripting


Closed    
 
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: 28 July 2016, 1:06 PM EDT
Location: Chennai, INDIA
Posts: 76
Thanks: 14
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 09: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: 5 December 2016, 5:18 PM EST
Posts: 242
Thanks: 42
Thanked 78 Times in 74 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: 29 November 2016, 2:11 AM EST
Posts: 1,785
Thanks: 97
Thanked 621 Times in 554 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: 12 June 2016, 11:03 PM EDT
Location: /dev/ph
Posts: 4,996
Thanks: 73
Thanked 475 Times in 437 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: 28 July 2016, 1:06 PM EDT
Location: Chennai, INDIA
Posts: 76
Thanks: 14
Thanked 0 Times in 0 Posts
Thank you all for your reply.

Thank you so much.

Krishna
Sponsored Links
Closed

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 11: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 06: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 02:08 PM
Unix grep/test command netmaster UNIX for Dummies Questions & Answers 4 05-08-2009 03:05 AM
the TEST command marwan UNIX for Dummies Questions & Answers 2 04-23-2007 07:51 PM



All times are GMT -4. The time now is 08:23 AM.