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
gcd.sh script doesn't work... kantze Shell Programming and Scripting 1 01-17-2008 09:46 PM
Modify Perl script to work with txt - Permissions script joangopan Shell Programming and Scripting 1 09-12-2007 11:38 PM
Why does this script not work? Please help duke0001 Shell Programming and Scripting 4 02-22-2007 09:28 PM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 10:52 PM
sed script. How does it work? billy5 Shell Programming and Scripting 2 09-02-2005 04:45 PM

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

Join Date: Jun 2007
Posts: 10
My script does not work - could you pls help?

Hi all,
I put together a script that seems not working as I would like to and after spending hours to find the problem I decided to ask your help.
The thing I am trying to do is call AWK command on the TRUE branch of if statement. Else branch should only print out a message to screen.

This is the code I am using:


...
for printer in "$@" ; do
lpstat $printer|grep $printer |grep '-' >$TEMP_FILENAME
grep '-' $TEMP_FILENAME
status=$?
if [[$status -eq 0]] ; then
awk '
{
here I do some stuff...
}
' $TEMP_FILENAME
else
echo "No jobs in the printer queue $printer ..."
fi
done


The result I got is not what I expect:
printerjob1 user priority 0 Jun 27 08:26
printerjob2 user priority 0 Jun 28 13:38
./prg.sh[103]: [[0: not found
No jobs in the printer queue printername ...


So for me it seems program executes somehow both branches of the IF statement.
The line 103 where the problem is indicated is:
if [[$status -eq 0]] ; then

I could not solve it , so please recommend me what the problem might be...

Thank you!
BearCheese
  #2 (permalink)  
Old 06-29-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Leave a space before $status and after 0
Code:
if [[ $status -eq 0 ]] ; then
If you have q option with grep which gives the exit status, try this
Code:
if grep -q '-' $TEMP_FILENAME ;then 
awk '
{ 
here I do some stuff...
}
' $TEMP_FILENAME
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 12:17 PM.


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