f



I don't get why '>' doesn't get printed in the following example

When I do a here-document, the '>' character shows up to indicate the
start of a newline.

[cdalten@localhost ~]$ cat << EOF
> My current directory is dir $PWD
> EOF
My current directory is dir /home/cdalten
[cdalten@localhost ~]$


What prevents the '>' characters from showing up in the final output?
0
Chad
7/3/2009 2:35:19 PM
comp.unix.shell 15484 articles. 2 followers. Post Follow

3 Replies
1268 Views

Similar Articles

[PageSpeed] 52

On Jul 3, 10:35 am, Chad <cdal...@gmail.com> wrote:
> When I do a here-document, the '>' character shows up to indicate the
> start of a newline.
>
> [cdalten@localhost ~]$ cat << EOF> My current directory is dir $PWD
> > EOF
>
> My current directory is dir /home/cdalten
> [cdalten@localhost ~]$
>
> What prevents the '>' characters from showing up in the final output?

The ">" character being shown is a prompt, not an actual character
included in the data that was input. If you use that logic, why
doesn't the EOF show up?

The shell simply uses that ">" as a positional marker so you know
where to type, and that you are not in the base shell prompt of "$",
just like the value of $PS1 does not automatically become part of the
command line you type in.

SteveN
0
steven_nospam
7/3/2009 2:55:16 PM
On Jul 3, 7:35 am, Chad <cdalten@gmail.com> wrote:
> When I do a here-document, the '>' character shows up to indicate the
> start of a newline.
>
> [cdalten@localhost ~]$ cat << EOF> My current directory is dir $PWD
> > EOF
>
> My current directory is dir /home/cdalten
> [cdalten@localhost ~]$
>
> What prevents the '>' characters from showing up in the final output?

It's not showing up to indicate the start of a newline.  Have a look
at
sh(1), notably PS2.  Essentially, the shell prompts with PS2 when it
requires more input to complete a partial command.  E.g. one has given
one or more lines of input to the shell, but the input isn't yet
syntactically complete - the shell needs more input to complete the
command - so it prompts with PS2.  Some examples:
$ echo 'foo
> bar'
foo
bar
$ for tmp in 1 2; do echo "$tmp"
> done
1
2
$ cat << \__EOT__
> stuff for
> here doc
> __EOT__
stuff for
here doc
$ if false; then echo false
> fi
$
0
Michael
7/3/2009 3:13:26 PM
Chad <cdalten@gmail.com> writes:

> When I do a here-document, the '>' character shows up to indicate the
> start of a newline.
>
> [cdalten@localhost ~]$ cat << EOF
>> My current directory is dir $PWD
>> EOF
> My current directory is dir /home/cdalten
> [cdalten@localhost ~]$
>
> What prevents the '>' characters from showing up in the final
> output?

The same thing that prevents '[cdalten@localhost ~]$' showing up --
they are both prompts generated by the shell to help you know what is
expected.  Neither of them is seen by the program you run (cat in this
case).

-- 
Ben.
0
Ben
7/3/2009 3:41:02 PM
Reply: