LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   warning in command's output , but why ! (https://www.linuxquestions.org/questions/linux-newbie-8/warning-in-commands-output-but-why-4175421944/)

tushar_pandey 08-13-2012 10:43 PM

warning in command's output , but why !
 
test_3 & test_4 have hey_yo text

daa@daa-Aspire-5740:~$ cat test_4 << test_3
> ahaa
> bash: warning: here-document at line 91 delimited by end-of-file (wanted `test_3')

hey yo

questions are ::
1. why this warning ?
2. why shell is showing > symbol after cat test_4 << test_3 !

kbp 08-14-2012 12:22 AM

The format of the command you entered ('<<') is called a here-document. It allows you to input multiple lines like so:

Code:

cat <<EOF > /etc/resolv.conf
search my.madeup.domain
nameserver 192.168.0.1
EOF

The 'EOF' sequence above is arbitrary and defines a pattern to match when the multiline input is finished. You could just as easily use:
Code:

cat <<monkeysuncle > /etc/resolv.conf
search my.madeup.domain
nameserver 192.168.0.1
monkeysuncle

The command you entered was waiting for 'test_3' on a line by itself to complete the here-document.

tushar_pandey 08-14-2012 01:25 AM

Sir "kbp"

i am confused , i am not getting the actual meaning of < & > & << & >>
i know that they are related to input and output .

but please think about this

daa@daa-Aspire-5740:~/only_for_unix$ cat > f_1
hey ya , i am 305
daa@daa-Aspire-5740:~/only_for_unix$ cat < f_1 > f_2

why i am getting output in the screen and thats why i am thinking that there is a precedence in commands also ( like 'C' language) !

please , its a request that clarify this cat < f_1 > f_2 !

kbp 08-14-2012 04:18 AM

It's probably easier to point you to an existing reference, let us know if it's still unclear after you've read this:
http://tldp.org/LDP/abs/html/io-redirection.html

David the H. 08-14-2012 07:34 AM

Please use ***[code][/code] tags*** around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, bolding, colors, or other fancy formatting.

Also, please don't print your entire prompt line when it's not needed. It makes your code more confusing to read. Limit your post to only things that are important for the conversation.


Quote:

2. why shell is showing > symbol after cat test_4 << test_3 !

Because the shell considers the command to be an unfinished multi-line here document, it prints your PS2 prompt and waits for further input from you.

Quote:

$ cat > f_1
hey ya , i am 305
$ cat < f_1 > f_2

The cat command simply copies stdin (or the contents of files) to stdout, like a pipe connecting two sources.

The command "cat > f_1" will redirect anything it receives to file f_1, but since there are no input filenames or "<" redirects given, the input can only come directly from you. Did you type "hey ya , i am 305" yourself after the command? Because that's the only way it would show up normally. Generally running cat with no input means that it will just sit there waiting for some (until it's killed or receives a ctrl+D EOF signal). If you type something and hit enter, it will be redirected directly into the file.

"cat < f_1 > f_2" simply copies the current contents of f_1 into f_2.

If you run "cat < f_1", with no output file, then the contents of file f_1 are printed directly to your terminal, the default stdout.

tushar_pandey 08-14-2012 07:46 AM

sorry for mistake ,

its seems , that if i have added any output file to the syntax than it will not produce any input to the terminal !

unSpawn 08-14-2012 09:56 AM

Quote:

Originally Posted by tushar_pandey (Post 4753876)
sorry for mistake ,

Yeah, you shoudl be as you posted in the wrong forum as well. Next time please watch where you post threads, OK?


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