Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Posts
    3

    Unanswered: 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
    ====================================

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Chances are there are trailing spaces
    What does the below show?
    echo "zzz${RS}yyy"
    try pipe output to awk '{print $1}'

  3. #3
    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

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Yes, try to delete the <line feed> with tr e.g.
    RS=`$SQL_PLUS -silent user/passwd @../sql/dwh_start.sql | tr d "\n" `

  5. #5
    Join Date
    Oct 2005
    Posts
    3

    Thumbs up

    ... it works! Thx a lot!
    Uwe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •