The UNIX and Linux Forums  

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
echo statement when find returns null tchoruma UNIX for Dummies Questions & Answers 2 09-24-2009 08:13 AM
PEM_read_RSAPublicKey returns NULL Treasa High Level Programming 1 11-20-2008 09:22 AM
gethostbyname_r returns NULL when hostname has dash uunniixx IP Networking 12 06-04-2008 02:02 AM
compare null with non-null nitin Shell Programming and Scripting 8 11-04-2006 07:58 PM
longjmp never returns axes High Level Programming 2 09-10-2006 09:22 PM

Reply
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 10-01-2009
frenkelor frenkelor is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 3
awk returns null?

hi
i try to check if awk returns null
and i dont know how it's works

this is the command
set EndByC = `ls -l $base | awk '/.c$/ {print $9}'`
if ($EndByC=="") then #check if ther is XXX.c directory
echo Sorry ther is no XXX.c folder "in" $base path
echo the XXX.c folder is necessary to build the Makefile, please check again the path of this folders
exit 1
10X
or
  #2 (permalink)  
Old 10-01-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,125
Hi.

Are you testing if any C files exist?

You can use something like

Code:
ls $base/*.c > /dev/null 2>&1
if [ $? -ne 0 ]; then #no files
  echo Sorry ther is no XXX.c folder "in" $base path
  echo the XXX.c folder is necessary to build the Makefile, please check again the path of this folders
  exit 1
fi

ls will return an error (2) if no files exist, so there's really no need for awk, actually.

Assuming "$base" is a directory, ls will never return "NULL" with the -l option.


Code:
mkdir BLAH
ls -l BLAH
 
total 0

  #3 (permalink)  
Old 10-01-2009
jp2542a jp2542a is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 142
awk doesn't/can't return null. It's return (as an int) can be set by the exit directive....
  #4 (permalink)  
Old 10-01-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,125
Quote:
Originally Posted by jp2542a View Post
awk doesn't/can't return null. It's return (as an int) can be set by the exit directive....
I believe the O/P means an empty string.
  #5 (permalink)  
Old 10-01-2009
frenkelor frenkelor is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 3
ok
$base is a directory that should end with ".c" so i wont to check if any XXX.c dirs are exist
what it's > /dev/null 2>&1
end [ $? -ne 0 ]?
  #6 (permalink)  
Old 10-01-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,125
Ok, too much!


Code:
if [ -d $base ]; then
  echo directory $base exists
else
  echo directory $base does not exist
fi


Worry about the other stuff later...
  #7 (permalink)  
Old 10-01-2009
frenkelor frenkelor is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 3
sorry again
$base - is the path that given to the script
and in this path($base) i need a list of all the ???.c directory
and if there is not ???.c dir.. print error
???.c-(any directory that end with .c)
ok?
Reply

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 04:28 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