The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
TAHI Test Suite 4.0.2 (Self-Test Test Suite branch) iBot Software Releases - RSS News 0 07-10-2008 07:50 AM
TAHI Test Suite 3.0.15 (IPv6 Conformance Test Tool branch) iBot Software Releases - RSS News 0 07-10-2008 07:50 AM
TAHI Test Suite 3.0.13 (IPv6 Conformance Test Tool branch) iBot Software Releases - RSS News 0 04-06-2008 01:20 PM
test and .test in same directory vikashtulsiyan SUN Solaris 14 12-28-2007 02:25 AM
Keithley Introduces Linux-Based RF Parametric Test Systems - Test and Measurement.com iBot UNIX and Linux RSS News 0 07-23-2007 11:30 AM

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 08-01-2008
big123456 big123456 is offline
Registered User
  
 

Join Date: May 2005
Posts: 200
test if

Hi,
I have this script :

Code:
Nbr_BD_Link=`
sqlplus -S sysadm/${PSWD}@${DB_Name} << EOF
        set head off feedback off  ;
        select count(*) from dba_db_links ;
        exit ;
EOF `
echo "Nbr_BD_Link is : "
echo ${Nbr_BD_Link}
echo "we do a test"
if [ "${Nbr_BD_Link}" != "0" ] ; then
echo "${T80}\nLa base ${DB_Name} contient ${Nbr_BD_Link} DB Link :"
fi

The result of execution is

Code:
Nbr_BD_Link is :
0
we do a test
--------------------------------------------------------------------------------
La base MYDB contient
         0 DB Link :

As you can see, the conditional echo "${T80}\nLa base ${DB_Name} contient ${Nbr_BD_Link} DB Link :" is executed even if Nbr_Bd_Link is zero.
Now I force Nbr_BD_Link to be zero :

Code:
Nbr_BD_Link=0
Nbr_BD_Link=`
sqlplus -S sysadm/${PSWD}@${DB_Name} << EOF
        set head off feedback off  ;
        select count(*) from dba_db_links ;
        exit ;
EOF `
echo "Nbr_BD_Link is : "
echo ${Nbr_BD_Link}
echo "we do a test"
Nbr_BD_Link=0
if [ "${Nbr_BD_Link}" != "0" ] ; then
echo "${T80}\nLa base ${DB_Name} contient ${Nbr_BD_Link} DB Link :"
fi

The result would be

Code:
Nbr_BD_Link is :
0
we do a test

The condition is respected and the conditional echo "${T80}\nLa base ${DB_Name} contient ${Nbr_BD_Link} DB Link :" is not executed.
Why ? Any idea ?
Any help ? thank you.
May be some caracter at the end of Nbr_BD_Link ? How to keep just zero ?
  #2 (permalink)  
Old 08-01-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
As you can see from the output and expect from your script, it has a leading newline and some spaces. Take out the newline just after the opening backtick and/or use a comparison operator which is slightly less picky about whitespace (I tend to recommend case over if test).
  #3 (permalink)  
Old 08-01-2008
big123456 big123456 is offline
Registered User
  
 

Join Date: May 2005
Posts: 200
Thank you.
How Take out the newline just after the opening backtick ?
iTRIED FOR CASE /
:man case
Manual entry for case not found or not installed.
[:man select
Manual entry for select not found or not installed.
[:man CASE
Manual entry for CASE not found or not installed.

Last edited by big123456; 08-01-2008 at 10:17 AM..
  #4 (permalink)  
Old 08-01-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
case is a shell built-in, like if and while; it's documented in the sh manual page. If you have bash (or, I suppose, any of a number of other modern shells), try help case

You have a newline before "sqlplus"; by "take out the newline" I meant, move the sqlplus command to the same line as the opening backtick.


Code:
Nbr_BD_Link=`sqlplus -S sysadm/${PSWD}@${DB_Name} << EOF
        set head off feedback off  ;
        select count(*) from dba_db_links ;
        exit ;
EOF `
echo "Nbr_BD_Link is '${Nbr_BD_Link}'"
echo "we do a test"
case ${Nbr_BD_Link} in
  *[1-9]*) echo "${T80}\nLa base ${DB_Name} contient ${Nbr_BD_Link} DB Link :" ;;
esac

Note the addition of single quotes in the diagnostic "Nbr_BD_Link is '...'" -- those are there just to help you see any possible leading or trailing whitespace.

Last edited by era; 08-01-2008 at 10:35 AM.. Reason: Also suggest "help case"
  #5 (permalink)  
Old 08-01-2008
big123456 big123456 is offline
Registered User
  
 

Join Date: May 2005
Posts: 200
Thank you.
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 07:21 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