Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

What does a > prompt in Linux mean

Posted on 2014-04-26
8
Medium Priority
?
498 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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 20

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
The main intent of this article is to make you aware of ‘Exchange fail to mount’ error, its effects, causes, and solution.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

610 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