If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help with "case"

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-25-05, 04:20
uwe_db uwe_db is offline
Registered User
 
Join Date: Oct 2005
Posts: 3
Help with "case"

I'm confused about the matching with case. When i start the start.sh, the RS Variable is filled with "1". But is not recognized by the case statement. I allways run into the "no match" clause. If i fill "RS" manually with "1" (RS=1) then it works fine. Does someone know the rreason why?
thx in advance
Uwe

Note: the "1" in the Log-File is my Test-Output (... echo $RS >> mytest.log)

=====================================
# start.sh:

RS=`$SQL_PLUS -silent user/passwd @../sql/dwh_start.sql`
echo " Start :" $RS >> ../log/dwh_start.log
echo $RS >> mytest.log
case $RS in
1) echo 'wert nr 1' >> mytest.log ;;
'1') echo 'wert nr 1a' >> mytest.lo ;;
"1") echo 'wert nr 1b' >> mytest.log ;;
*) echo 'no match' >> mytest.log ;;
esac

=====================================
-- dwh_start.sql:

SET HEAD OFF
SET TERMOUT ON
SET SERVEROUTPUT OFF
SET DEFINE ON
SET FEEDBACK OFF
SET VERIFY OFF
select aktiv from T_SYS_ABLAUFST
where to_char(datum, 'dd.mm.rrrr') = to_char(sysdate,'dd.mm.rrrr');
quit;

===================================
-- mytest.log:
1
no match
====================================
Reply With Quote
  #2 (permalink)  
Old 10-25-05, 05:28
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Chances are there are trailing spaces
What does the below show?
echo "zzz${RS}yyy"
try pipe output to awk '{print $1}'
Reply With Quote
  #3 (permalink)  
Old 10-25-05, 07:20
uwe_db uwe_db is offline
Registered User
 
Join Date: Oct 2005
Posts: 3
... i did what you said:

#====================
# start.sh:

RS=`$SQL_PLUS -silent dwhrun/plato130 @../sql/dwh_start.sql`
echo " Start :" $RS >> ../log/dwh_start.log
echo $RS >> mytest.log
echo "zzz${RS}yyy" >>mytest.log

case $RS in
1) echo 'wert nr 0' >> mytest.log ;;
'1') echo 'wert nr 1a' >> mytest.lo ;;
"1") echo 'wert nr 1b' >> mytest.log ;;
4) echo 'wert nr 2' >> mytest.log ;;
*) echo 'no match' >> mytest.log ;;
esac

#====================================

... and got the following ouput in my log-file:

======================================
--mytest.log:

1
zzz
1yyy
no match
======================================

... --> does it mean that i have a <carridge return> or <line feed> at the beginning of "RS"? How can i put this to my clauses in the "case"-Statement?

thx
Uwe
Reply With Quote
  #4 (permalink)  
Old 10-26-05, 02:54
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Yes, try to delete the <line feed> with tr e.g.
RS=`$SQL_PLUS -silent user/passwd @../sql/dwh_start.sql | tr –d "\n" `
Reply With Quote
  #5 (permalink)  
Old 10-26-05, 05:22
uwe_db uwe_db is offline
Registered User
 
Join Date: Oct 2005
Posts: 3
Thumbs up

... it works! Thx a lot!
Uwe
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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