LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sqlplus not working within if condition (https://www.linuxquestions.org/questions/linux-newbie-8/sqlplus-not-working-within-if-condition-4175459830/)

sysmicuser 04-27-2013 09:10 PM

sqlplus not working within if condition
 
Guys,

I am not sure what is the problem but somehow this is not working :(

Code:

#!/bin/sh
export TNS_ADMIN=/path to tnsnames.ora
export password=my_password;
export day="sunday"
        if [[ day = 'sunday' ]];  then
        sqlplus username/${password}@orcl << EOF
        set echo on
        set serveroutput on
        insert into table_temp(col_date,file_name,status) values(sysdate,'XYS','success');
        commit;
        exit;
        EOF
        else
        echo "NO"
                fi


kooru 04-28-2013 01:45 AM

Hi,

a right way is:

Code:

..
if [ "$day" == "sunday" ]; then
..

http://tldp.org/LDP/abs/html/comparison-ops.html

chrism01 04-28-2013 06:53 AM

If you use double [[ ]] http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS, you don't need to quote the values there.
Incidentally, no need to export stuff either, that's only if you want the vars to appear in a subshell.

sysmicuser 05-03-2013 06:10 AM

@chrism01.

I am inexperienced person, may you enlighten me with your rich shell scripting experience.

So if i use [[ ]] then i don't have to use " inside those brackets? so we need to export the variable only if I want to use them in subshell? so I don't want to export how can I initialise the variable? Please explain thanks.

chrism01 05-03-2013 08:46 AM

Try this for 'export' http://stackoverflow.com/questions/1...without-export

sysmicuser 05-03-2013 09:49 AM

@chrism01.

I have seen people using SET, DEFINE or LET keywords used to define variables, can you shed some light there as well please ?

Many Thanks in advance !


All times are GMT -5. The time now is 03:41 AM.