?
Solved

What does a > prompt in Linux mean

Posted on 2014-04-26
8
Medium Priority
?
489 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 1000 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1000 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 500 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

765 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