I do not know how valid this post is, but here it is.
I was writing a script for testing some development code that I had written. It involved many echo statements to redirect the output into a log file.
Given the large number of echo statements, I took to this solution
Code:
cat <<EOF >> /tmp/log
A Line in the log file.
The next line in the log file.
And the last line in the log file.
EOF
which will produce
Code:
$ cat /tmp/log
A Line in the log file.
The next line in the log file.
And the last line in the log file.
Since there were many occurences of these cat command (and also being a case of UUOC), I thought of using the here-document in the following manner to arrive at the same solution as above.
Code:
echo <<EOF >> /tmp/log
A Line in the log file.
The next line in the log file.
And the last line in the log file.
EOF
But in this case, /tmp/log was empty.
Look at the man pages of sh and ksh, it says
Code:
ksh
<< marker
after reading the command line containing this kind of redirec-
tion (called a here document), the shell copies lines from the
command source into a temporary file until a line matching
marker is read. When the command is executed, standard input is
redirected from the temporary file.
Code:
sh
Here Documents
This type of redirection instructs the shell to read input from the
current source until a line containing only word (with no trailing
blanks) is seen. All of the lines read up to that point are then used
as the standard input for a command.
Basically, the here document would be written into some temporary file and then re-read. If that be the case, why doesnt the echo with here documents work ?
I went through the The Open Group Base Specifications Issue 6 - UNIX Specification for echo and here-document. They dont say anything in particular about this.
ssh $USR@$host /bin/bash <<\EOF >> ship-error.txt
awk 'BEGIN{f=0} !f { s=$0; sub(/,.+/, "", s); gsub(//, " ", s); t=(systime()-mktime(s)); if(t<=14400) f=1 } f ' /logs/shiperror.log
EOF
I want to use an echo command within the EOF. Is this possible?
something like this: So that it prints... (3 Replies)
Can we use a here document inside a here document?
Something like this
ssh user@remotehost << REMOTE
sudo vserver vsernamename enter << VSERVER
perform actions on vserver.
VSERVER
REMOTE (6 Replies)
echo `echo ` doesn't echoes anything. And it's logic. But
echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo"
(too much echoing :P):o (2 Replies)
Bit of a weird one i suppose, i want to use an echo inside an echo... For example...
i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos...
echo "echo "hello"" >$file
echo "echo "goodbye"" >$file
... (3 Replies)
So in my shell i execute:
{ while true; do echo string; sleep 1; done } | read line This waits one second and returns.
But
{ while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly.
I have tried this in bash as well as zsh,... (2 Replies)
Here is my problem: can we set the variables in the HERE DOCUMENT? I have tried but failed. Any one has good comments please let me know.
#!/bin/csh -f
pbrun -u xmgbrk runshell <<!
@ $num1 = `wc -l /home/tpltp/csh/scripts/who.csh`
echo "$num1"
if ( $num1 > 0 ) then
echo $num1 | tee -a... (1 Reply)
Plz can somebody give me the shell and perl scripting documents,i need to start the scrpts learning.now i know about the linux commands,but need help in putting the same in the scripting with do,if,while and also using diffrent commands in the scrpipts,pls help.. (3 Replies)
Hi :)
how can I use here doc to use ssh?
I am facing a problem with the below script:
#!/bin/bash
ssh hosein@localhost << *
123456
*
"123456" is my password
Thanks (2 Replies)
Hello,
I want to know the use of the here document with the << operator.
Tried to go through some books but the concept was not clear.
Please can any1 expalin me this with a simple example.
Thanks,
Rahul. (6 Replies)
I understand that a Here Document will redirect all of the lines between the beginning marker for the here document and the ending marker into the command specified just as if the text were coming from standard input.
I am trying to understand the Here Document with this example:
# Menu file... (3 Replies)