LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-27-2013, 10:10 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 334

Rep: Reputation: 0
Unhappy 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
 
Old 04-28-2013, 02:45 AM   #2
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 273Reputation: 273Reputation: 273
Hi,

a right way is:

Code:
..
if [ "$day" == "sunday" ]; then
..
http://tldp.org/LDP/abs/html/comparison-ops.html

Last edited by kooru; 04-28-2013 at 02:53 AM.
 
Old 04-28-2013, 07:53 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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.
 
Old 05-03-2013, 07:10 AM   #4
sysmicuser
Member
 
Registered: Mar 2010
Posts: 334

Original Poster
Rep: Reputation: 0
@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.
 
Old 05-03-2013, 09:46 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Try this for 'export' http://stackoverflow.com/questions/1...without-export
 
1 members found this post helpful.
Old 05-03-2013, 10:49 AM   #6
sysmicuser
Member
 
Registered: Mar 2010
Posts: 334

Original Poster
Rep: Reputation: 0
@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 !
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
check Negative egrep condition in an if condition novicunix Programming 5 02-02-2013 01:52 AM
want to install postgreSQL DB 9.1 with existing one (8.4) working condition on RH5 gadhave.vikas Linux - Server 1 10-06-2012 03:04 PM
want to install postgreSQL DB 9.1 with existing one (8.4) working condition on RH5 gadhave.vikas Linux - Newbie 1 10-05-2012 04:11 AM
[SOLVED] less than condition in if statement not working as desired samasat Linux - Newbie 11 06-09-2012 06:33 PM


All times are GMT -5. The time now is 03:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration