The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
here document not working JamesByars Shell Programming and Scripting 2 01-15-2008 04:41 PM
The here document << rahulrathod Shell Programming and Scripting 6 01-23-2006 12:05 AM
Teaching myself Here Document ericelysia UNIX for Dummies Questions & Answers 3 10-31-2005 12:33 AM
echo with a here-document vino Shell Programming and Scripting 2 08-19-2005 10:48 AM
How to split a document gtapia Shell Programming and Scripting 2 07-15-2004 06:25 PM

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 01-12-2006
jvander jvander is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 20
Sqlplus 'here' document: <<EOF vs. <<-EOF

Hi,

I've noticed two variations of embedded sqlplus 'here' documents used as input to sqlplus. Most examples seem to use the following format with EOF (or some other unique identifier) directly appended to the << as shown below.

sqlplus -s /nolog <<EOF
connect username/password@mydatabase

select.........
.................
/
EOF

Another variation is almost identical except that << is separated from EOF by a '-', as in <<-EOF.

I've been searching the documentation and other threads and cannot find the significance of one vs. the other. Is there any functional difference between <<- and << ? is one better than the other?

Thanks!
  #2 (permalink)  
Old 01-12-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
From the ksh man page: "If - is appended to <<, all leading tabs are stripped from word and from the document."
  #3 (permalink)  
Old 01-12-2006
fidodido fidodido is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 49
Perderabo, care to post a 'for example' ? Sorry for my ignorance, but sometimes my english is not as good as it should be when reading stuff.
  #4 (permalink)  
Old 01-21-2006
tej.buch tej.buch is offline
Registered User
  
 

Join Date: Jan 2006
Location: Gandhinagar, India
Posts: 25
hi did u get the reason for that?

not only that,i have tried out diff possibilities and i find that you can use any string consisting of one or more letters and numbers...

i tried to ask pepl but didnt get any a satisfactory answer

also in

-------------------<< X
statements...
....

Y

kind of blocks that u just mentioned....it is also not necessary that X be equal to Y....

i hope ur gettin what i mean to convey..

ok then...wil wait for ur reply...
bye
  #5 (permalink)  
Old 01-21-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
An example of here document in the <<-WORD form :


Code:
$ sqlplus <<-EOD_SQL
        connect username/password@mydatabase
        select ........
        EOD_SQL
$

Tab before EOD_SQL is mandatory !
  #6 (permalink)  
Old 01-21-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
The value of this feature becomes more clear when the here-doc is moved to an inner block...
Code:
#! /usr/bin/ksh

i=0
while ((i<4)) ; do
        cat <<-EndOfData
                Attention: some important message
                that goes to several lines
                like this
                EndOfData
        ((i=i+1))
done
exit 0


#! /usr/bin/ksh

i=0
while ((i<4)) ; do
        cat <<EndOfData
Attention: some important message
that goes to several lines
like this
EndOfData
        ((i=i+1))
done
exit 0

Second example looks nasty and it gets worse with more deeply nested loops. But until <<- arrived, first example was not possible. Remmember though this works tabs only, not spaces.
  #7 (permalink)  
Old 01-22-2006
tej.buch tej.buch is offline
Registered User
  
 

Join Date: Jan 2006
Location: Gandhinagar, India
Posts: 25
'here' block

hi thanks for the examples..

but there is one more thing that stumps me...
how does a 'here' block conceptually work...?

i mean what is the control flow and why does it so happen that the thing written within the here block is executed by that coresspong application..

also can u pls give an example for the bash shell?

thanks agai...
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 03:15 PM.


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