Solved

What does a > prompt in Linux mean

Posted on 2014-04-26
8
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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
 
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 62

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 62

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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