Solved

What does a > prompt in Linux mean

Posted on 2014-04-26
8
460 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.

707 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

21 Experts available now in Live!

Get 1:1 Help Now