LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-06-2007, 09:50 PM   #1
tlaresearch
LQ Newbie
 
Registered: Jul 2003
Posts: 15

Rep: Reputation: 0
Here-document problems


I am trying to automate starting a program that has a command line interface with a here document. I want the here document to initialize the program with commands, then let it run. The problem is that after the last command is given to the program, it acts like it's still getting commands from somewhere. The program echos commands that it receives, and it's saying that it is a null character, or a string of length zero. I tried redirecting the input from a file and I get the same results. Any ideas?

#!/bin/bash

echo "starting program"

./program <<%%
o
1
l
%%

echo "done."
exit 0
 
Old 10-06-2007, 10:02 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You need a terminator for your here document:

cat >file <<file2 EOF
line 1
line 2 - $1
EOF
 
Old 10-06-2007, 10:21 PM   #3
tlaresearch
LQ Newbie
 
Registered: Jul 2003
Posts: 15

Original Poster
Rep: Reputation: 0
I don't follow your example - it's quite a different format than the shell script I posted. I thought the here document starts with the tag (%% in my case) and ends with the same tag. Do I need a terminator in addition to what I have?

Thanks for your help.
 
Old 10-06-2007, 10:44 PM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.

I think your shell syntax is OK:
Code:
#!/bin/sh -

# @(#) s1       Demonstrate here documents, non-alphanumeric tokens.

cat <<%%
one
two
three
|
%%

exit 0
Producing:
Code:
% ./s1
one
two
three
|
which suggests to me that the problem lies in your program ... cheers, makyo
 
Old 10-07-2007, 10:37 AM   #5
Tischbein
Member
 
Registered: Oct 2006
Distribution: debian
Posts: 124

Rep: Reputation: 15
To make doubly certain you could use a non-here document to confirm:

# To print out arguments one per line:
> printf '%s\n' 0 1 0 1 '|'
0
1
0
1
|
> printf '%s\n' 0 1 0 1 '|' | ./yourprog


Lykke til!
 
  


Reply

Tags
document, here, special, token



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
docbook document problems Mig21 Slackware 3 12-15-2006 07:08 PM
Suse 10 as Server and document problems awtoc123 SUSE / openSUSE 1 03-08-2006 09:15 AM
how do i create a document, then a directory and save the document in it. jtdodge Linux - Newbie 9 06-15-2005 11:03 AM
Some really interesting document? Lead Expression Linux - General 2 01-07-2005 05:52 AM
Convert openoffice document into ms document through cli? bruno buys Linux - Software 0 07-05-2004 09:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:22 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
Open Source Consulting | Domain Registration