Solved

What does a > prompt in Linux mean

Posted on 2014-04-26
8
465 Views
Last Modified: 2014-05-11
When I run the following command:

cat <<word My text word
>

and hit enter the prompt changes to a > and I have to hit ctrl + c to get out of that.

My intention was to have a screen output of My text but I have since found out that this will work in a shell script.

#!/bin/bash
cat <<word My text word

and if I name the script myscript and run the script I will get the desired effect of reading the text until it gets to my delimiter which is word.

./myscript
My text

So the << is used to produce a here document and I have looked at the man page but I still don't know what the > sign means.

http://linux.die.net/abs-guide/here-docs.html

I am curious what the > prompt is asking for or what it is doing?

Thank you
0
Comment
Question by:Dragon0x40
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 40024910
The prompt indicates that the shell is waiting for your input (actually for a continuation) until the end-of-input string is encountered ("word" in your first example) on a line of its own, starting at column 1. The shell will then complain about not being able to open "My", "text" and "word" nevertheless, because additional strings are not allowed after the delimiter specification.

Your "myscript" example can only work if there are linefeeds between "word" and "My text" and between "My text" and "word" and if "word" starts at column 1 on a line of its own (see above).
0
 

Author Comment

by:Dragon0x40
ID: 40024972
You are correct my script actually looks like this.

#!/bin/bash
cat <<word
My text
word

so when I run it I see this:

 ./myscript
My text
0
 

Author Comment

by:Dragon0x40
ID: 40024976
cat <<word My text word
>

Is cat waiting for input?

If so what is it going to do with it?

I think that I have tried typing in "word" and pressing enter but it does not return me to the bash prompt.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 40024978
OK, that's how it works in a script.

On the command line type "cat <<word" without any additional stuff after "word" (!!) and hit <Enter>, then just type "My text" at the ">" prompt, hit <Enter>. The ">" will reappear. Type "word" and hit <Enter> again. You'll see the desired result.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 19

Assisted Solution

by:simon3270
simon3270 earned 125 total points
ID: 40025018
If you do want it all on one line, you can use the Bash construction "<<<" (a "here" string), as

    cat <<<"My text"

which will just display

    My text

(you need the quotes round the text, otherwise it will treat the first word as the here string, and the rest of the words as filename attributes to "cat")
0
 
LVL 61

Assisted Solution

by:gheist
gheist earned 125 total points
ID: 40025178
> prompt (actuallly $PS2 variable) means that you continue entry of the command. Either continue with your command or press Ctrl-C to get back to normal prompt.
0
 

Author Comment

by:Dragon0x40
ID: 40057586
#cat <<word My text word
>some
>text
>hitting enter after each word
>word
cat: My: No such file or directory
cat: text: No such file or directory
cat: word: No such file or directory
#cat >word
>my text
>word
my text
0
 
LVL 61

Expert Comment

by:gheist
ID: 40057593
Is it a homework question?

$ cat << EOD
>abc
>def
EOD

Would do same as cat FILE, where FILE has content of whatever was typed between EOD markers

$ cat > word
> x
>y
text
Ctrl-D

Will rewrite file "word" (or file pointed to by symlink called word)  with all that was typed until EOF marker (typically EOF=^D)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux Scripting 3 103
nagios alerts 3 33
Installation of Nessus Professional 5 84
Setting up two Raspberry Pi gateways/routers 3 43
A list of useful business intelligence software.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The viewer will learn how to set up a document for the web and print and the recommended PPI for printing.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now