Visit Our UNIX and Linux User Community

Full Discussion: echo with a here-document
Top Forums Shell Programming and Scripting echo with a here-document Post 81409 by Unbeliever on Friday 19th of August 2005 09:48:51 AM
Old 08-19-2005
I assume its because echo (unlike most unix commands) does not 'by default' read from the stdin descriptor. All these commands simply echo a new line:

a) echo "mystring" | echo
b) cat myfile | ehho
c) echo < myfile
d) echo <<EOF

So in your second example:
Originally Posted by vino
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.
you are in effect doing:

echo < myinfile > myoutfile

it's just the shell is creating the file for you.
Test Your Knowledge in Computers #218
Difficulty: Easy
A peer-to-peer network sets all connected computers equal and all connected computers share the same abilities to use resources available on the network.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Teaching myself Here Document

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)
Discussion started by: ericelysia
3 Replies

2. Shell Programming and Scripting

The here document <<

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)
Discussion started by: rahulrathod
6 Replies

3. Shell Programming and Scripting

ssh and here document

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)
Discussion started by: htabesh
2 Replies

4. Shell Programming and Scripting


Plz can somebody give me the shell and perl scripting documents,i need to start the scrpts 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)
Discussion started by: satish.res
3 Replies

5. Shell Programming and Scripting

Variables in HERE DOCUMENT

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)
Discussion started by: tpltp
1 Replies

6. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

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)
Discussion started by: ulidtko
2 Replies

7. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

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)
Discussion started by: mokachoka
3 Replies

8. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

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)
Discussion started by: hakermania
2 Replies

9. Shell Programming and Scripting

Here document inside a here document?

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)
Discussion started by: mnanavati
6 Replies

10. Shell Programming and Scripting

How to echo within EOF (here-document)

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)
Discussion started by: Deepthz
3 Replies
STRPOS(3)								 1								 STRPOS(3)

strpos - Find the position of the first occurrence of a substring in a string

mixed strpos (string $haystack, mixed $needle, [int $offset]) DESCRIPTION
Find the numeric position of the first occurrence of $needle in the $haystack string. PARAMETERS
o $haystack - The string to search in. o $needle - If $needle is not a string, it is converted to an integer and applied as the ordinal value of a character. o $offset - If specified, search will start this number of characters counted from the beginning of the string. Unlike strrpos(3) and strri- pos(3), the offset cannot be negative. RETURN VALUES
Returns the position of where the needle exists relative to the beginning of the $haystack string (independent of offset). Also note that string positions start at 0, and not 1. Returns FALSE if the needle was not found. Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. EXAMPLES
Example #1 Using === <?php $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // Note our use of ===. Simply == would not work as expected // because the position of 'a' was the 0th (first) character. if ($pos === false) { echo "The string '$findme' was not found in the string '$mystring'"; } else { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } ?> Example #2 Using !== <?php $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // The !== operator can also be used. Using != would not work as expected // because the position of 'a' is 0. The statement (0 != false) evaluates // to false. if ($pos !== false) { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } else { echo "The string '$findme' was not found in the string '$mystring'"; } ?> Example #3 Using an offset <?php // We can search for the character, ignoring anything before the offset $newstring = 'abcdef abcdef'; $pos = strpos($newstring, 'a', 1); // $pos = 7, not 0 ?> NOTES
Note This function is binary-safe. SEE ALSO
stripos(3), strrpos(3), strripos(3), strstr(3), strpbrk(3), substr(3), preg_match(3). PHP Documentation Group STRPOS(3)

Featured Tech Videos

All times are GMT -4. The time now is 11:40 PM.
Unix & Linux Forums Content Copyright 1993-2020. All Rights Reserved.
Privacy Policy