The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
test skooly5 UNIX for Dummies Questions & Answers 1 04-07-2008 06:38 AM
TAHI Test Suite 3.0.13 (IPv6 Conformance Test Tool branch) iBot Software Releases - RSS News 0 04-06-2008 09:20 AM
test and .test in same directory vikashtulsiyan SUN Solaris 14 12-27-2007 11:25 PM
Test : Which OS are you ? sysgate What's on Your Mind? 8 08-29-2007 03:36 PM
Keithley Introduces Linux-Based RF Parametric Test Systems - Test and Measurement.com iBot UNIX and Linux RSS News 0 07-23-2007 07:30 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-04-2005
Registered User
 

Join Date: Jul 2005
Posts: 12
Question test $#

Hi,
In one of the scripts i have seen this code

if test $# = 2
then
LOG_FILE=$2
else
LOG_FILE=$SYNC_PATH/logs/$BASENAME.log
fi

can someone help me with what " test $# " signifies..

Thanks in advance..
Reply With Quote
Forum Sponsor
  #2  
Old 10-04-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
$# holds the number of command line arguments passed to a shell script.

Look at this script.

Code:
[~/temp]$ cat shell.sh 
#! /bin/sh
echo $#
Code:
[~/temp]$ ./shell.sh 
0
[~/temp]$ ./shell.sh arg1
1
[~/temp]$ ./shell.sh arg1 agr2
2
[~/temp]$ ./shell.sh arg1 agr2-arg3
2
So if test $# = 2 evaluates whether the number of arguments passed is 2 or not.

See man test for more on test

Code:
if test $# = 2
is another of writing
Code:
if [ $# = 2 ]
Look under Special Parameters in man sh

vino

Last edited by vino; 10-04-2005 at 03:49 AM.
Reply With Quote
  #3  
Old 10-04-2005
Registered User
 

Join Date: Jul 2005
Posts: 12
GOT IT!!!

Thanks..
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0