The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to read record by record from a file in unix raoscb UNIX for Dummies Questions & Answers 1 05-16-2008 06:30 AM
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 01:14 PM
splitting a record and adding a record to a file rsolap Shell Programming and Scripting 1 08-13-2007 01:58 PM
compare null with non-null nitin Shell Programming and Scripting 8 11-04-2006 07:58 PM
How Many "Falling Unix Commands" are in the Flash Header? Neo Post Here to Contact Site Administrators and Moderators 10 01-22-2004 02:47 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-29-2006
TonyR TonyR is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 2
If statement falling over on a null record. Help please.

Okay i've got some code which reads a text file and loops through it and there a few if statements inside where one is failing (the one bolded).

Basically the acc column contains a list of three digit access codes, some though have null records (i.e nothing in the field) so what I want to do is if its not null to carry on to the other loops if it is null to move on to the next record.

I thought -n meant if the value is greater than 0 in length. I.e not null.

When it gets the the first null record i get the following error message

create_matrix_busy.exe: test: argument expected


This is my code so far...


while read line
do
sdate=`echo "$line" | cut -d, -f1`
edate=`echo "$line" | cut -d, -f2`
edate=`echo "$line" | cut -d, -f2`
site=`echo "$line" | cut -d, -f3`
NA=`echo "$line" | cut -d, -f4`
acc=`echo "$line" | cut -d, -f6`
calls=`echo "$line" | cut -d, -f8`
if [ -n ${acc} ]
then

if [ ${calls} -gt 0 ]
then
if [ ${NA} = 'ALL' ]
then
echo ${site},${acc}
elif [ ${NA} = 'NA*' ]
then
echo ${site},NA${acc}
fi
fi
fi

Thanks, the code will do more inside the if statements once i get those working.
  #2 (permalink)  
Old 04-29-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
if [ -n "${acc}" ]
  #3 (permalink)  
Old 04-29-2006
TonyR TonyR is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 2
Thank you.
  #4 (permalink)  
Old 04-29-2006
buffoonix buffoonix is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 145
If you are using a Posix shell you should switch to the double square brackets test operator
e.g.

if [[ -n $acc ]]; then
echo \$acc defined
fi
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0