Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The angle bracket in an echo command???

1,457 views
Skip to first unread message

g903

unread,
Nov 12, 1997, 3:00:00 AM11/12/97
to

Can anyone let me know why I'm getting error messages when I include
angle brackets ie < >in an echo command, such as:
echo Correct Usage is BLAH <filename>

Thanks Graham


ReadingSci

unread,
Nov 12, 1997, 3:00:00 AM11/12/97
to

>Can anyone let me know why I'm getting error messages when I include
>angle brackets ie < >in an echo command, such as:
>echo Correct Usage is BLAH <filename>

Sure. The angle brackets redirect output. It allows you to dump the line
being echoed to an alternate location, like a file. For example...

ECHO Correct Usage is BLAH > blah.txt

If you type BLAH.TXT, you'll see "Correct Useage is BLAH". You can also
redirect things to "nul". This is useful for things like PAUSE, when you
don't want to see "Press Any Key to Continue..."

PAUSE > NUL

If you use double angle brackets, it adds to the file, rather than replacing
it. Example...

ECHO Hello >> blah.txt

Now BLAH.TXT would contain...

Correct Useage is BLAH
Hello

Perhaps one of the other readers will know if it is possible to use ">" inside
of the ECHO without it redirecting. The above explains your problem, though.
8^)

============================================
Reading Scientific Co., Inc.
* Quality chemistry products from the most respected
suppliers and manufacturers in the industry.
http://members.aol.com/readingsci/readingsci.html
E-mail: Readi...@aol.com

Tom Lavedas

unread,
Nov 12, 1997, 3:00:00 AM11/12/97
to g903

g903 wrote:
>
> Can anyone let me know why I'm getting error messages when I include
> angle brackets ie < >in an echo command, such as:
> echo Correct Usage is BLAH <filename>
>

If intended strickly for display, the simplest solution is to inclose
the less than/greater than signs (< & >) with double quotes, something
like this ...

echo "Correct Usage is BLAH <filename>"

If the presence of the quotes is objectionable, follow them with the
backspace character (ASCII 8, [Ctrl-P followed by Ctrl-H in DOS EDIT)
and at least one more character. For example,

echo "^HCorrect Usage is BLAH <filename>"^H[space]

Where the ^H stands for the backspace character. Note the trailing
space after the second Ctrl-H. The backspace in an ECHO is
non-distructive. The extra character overwrites the offending quote.

There is another approach that uses characteristics of the PROMPT
command, but it is a bit more involved. I have developed a little batch
file to automate the process. I am in the process of adding a page to
my web site to explain its function and use. Briefly, the procedure,
ANSI.BAT, simplifies the use of dollar sign substitution symbols for the
troublesome less than/greater than and vertical bar characters. The
procedure has just four working lines:

:: ANSI.BAT - Makes using ANSI control sequences easy.
:: Tom Lavedas <tlav...@www.deltaelectronics.com>
:: http://www.deltaelectronics.com/tglbatch/
@echo %dbga% off
> %ram%.\}A{.bat echo @prompt %1
> %ram%.\}B{.bat %comspec% /e:2048/c }A{
for %%v in (%ram%.\}B{.bat del) do call %%v %ram%.\}?{.bat
:: A line needed to surpress extra line feed created by FOR

In your case, it would be called thus ...

set temp=Correct Usage is BLAH $lfilename$g
call ansi echo.%%temp%%
set temp=>nul

The two problem characters are replaced by the $l and $g substitutions.
I developed ANSI.BAT to help with displaying ANSI control strings (so
called Escape sequences), but have found it to be useful for all kinds
of things. Try, for example, ...

ansi echo.$_Date:$d$_Time:$t$_
or
ansi set$qDate$q$d$_set$qTime$q$t

For more information on the available substitutions try HELP PROMPT from
a command prompt.

Tom Lavedas
-----------
Delta Electronics, Inc.
http://www.deltaelectronics.com/tglbatch/

Geoff Cutter

unread,
Nov 13, 1997, 3:00:00 AM11/13/97
to

On Wed, 12 Nov 1997 14:28:30 +0800, g903 <g9...@peeltafe.wa.edu.au>
wrote:

>Can anyone let me know why I'm getting error messages when I include
>angle brackets ie < >in an echo command, such as:
>echo Correct Usage is BLAH <filename>
>

@echo @prompt Do it like this $l filename $g >2temp2.bat
@command/c 2temp2 >3temp3.txt
@type 3temp3.txt

Tested in Win95 DOS, however I suggest you don't use a statement
with < or > in this way as those symbols are used for redirection in
DOS. BTW, if it's the file name you want, use %0.

echo This file is %0


regds Geoff Thursday, 1997-11-13
gcu...@melbpc.org.au (address expires Mar 98)

Ted Davis

unread,
Nov 13, 1997, 3:00:00 AM11/13/97
to

In article <34694C8D...@bikerider.com>, g903 writes:
> Can anyone let me know why I'm getting error messages when I include
> angle brackets ie < >in an echo command, such as:
> echo Correct Usage is BLAH <filename>
>
> Thanks Graham
>


echo Correct Usage is "BLAH <filename>"

will work, as will

"echo Correct Usage is BLAH <filename>"

If you can live with the "", you can avoid rather a lot of work.


Muhammad Usman

unread,
May 13, 2023, 2:53:18 AM5/13/23
to
I got the solution just after 26 years. Use single quotes such as
echo -e '<!DOCTYPE html>'
will solve the issue.

If we use double quotes, it will surely raise an error.
echo -e "<!DOCTYPE html>"
```bash: !DOCTYPE: event not found```

Kerr-Mudd, John

unread,
May 13, 2023, 4:36:03 AM5/13/23
to
On Fri, 12 May 2023 23:53:16 -0700 (PDT)
Muhammad Usman <muhammadu...@gmail.com> wrote:

> I got the solution just after 26 years. Use single quotes such as

... and changing OS.

> echo -e '<!DOCTYPE html>'
> will solve the issue.
>
> If we use double quotes, it will surely raise an error.
> echo -e "<!DOCTYPE html>"
> ```bash: !DOCTYPE: event not found```
>

DOS: (actually a(n?) XP cmd window)

C:\>echo -e '<!DOCTYPE html>'
The system cannot find the file specified.



--
Bah, and indeed Humbug.

Muhammad Usman

unread,
May 13, 2023, 5:40:01 AM5/13/23
to
I was doing it on bash shell linux. Never tried it on DOS or windows

Kenny McCormack

unread,
Jun 14, 2023, 3:25:30 PM6/14/23
to
In article <51d52d53-aacf-40da...@googlegroups.com>,
Muhammad Usman <muhammadu...@gmail.com> wrote:
>On Saturday, 13 May 2023 at 13:36:03 UTC+5, Kerr-Mudd, John wrote:
>> On Fri, 12 May 2023 23:53:16 -0700 (PDT)
>> Muhammad Usman <muhammadu...@gmail.com> wrote:
>>
>> > I got the solution just after 26 years. Use single quotes such as
>> ... and changing OS.
>> > echo -e '<!DOCTYPE html>'
>> > will solve the issue.
>> >
>> > If we use double quotes, it will surely raise an error.
>> > echo -e "<!DOCTYPE html>"
>> > ```bash: !DOCTYPE: event not found```
...

>I was doing it on bash shell linux. Never tried it on DOS or windows

Then you posted to the wrong newsgroup.

Anyway, believe it or not, it is not the angle brackets that are giving you
grief (see below - *); rather, it is the exclamation point (!). You need to
read up on the topic of "history substitution" in "man bash".

(*) Basically, either single or double quotes will protect angle brackets,
but you need single quotes to protect "!".

--
Faith doesn't give you the answers; it just stops you from asking the questions.

Ivan Shmakov

unread,
Jun 15, 2023, 5:20:45 PM6/15/23
to
>>>>> On 2023-06-14, Kenny McCormack wrote:
>>>>> MU == Muhammad Usman <muhammadu...@gmail.com> wrote:

MU> I got the solution just after 26 years. Use single quotes such as
MU> echo -e '<!DOCTYPE html>'
MU> will solve the issue.

[...]

> Anyway, believe it or not, it is not the angle brackets that are
> giving you grief (see below - *); rather, it is the exclamation point
> (!). You need to read up on the topic of "history substitution" in
> "man bash".

> (*) Basically, either single or double quotes will protect angle
> brackets, but you need single quotes to protect "!".

It's also possible to disable history substitution altogether
with 'set +H'.

I believe this behavior is rather confusing to new users, and
given that C-r (reverse-search-history) and cursor keys already
offer a comparable feature, and one likely to fit better with
user's prior experience at that, my suggestion would be to
have it disabled by default.

--
FSF associate member #7257 http://am-1.org/~ivan/

Kenny McCormack

unread,
Jun 15, 2023, 5:39:22 PM6/15/23
to
In article <u6fvb9$hdk2$1...@dont-email.me>,
Ivan Shmakov <iv...@siamics.netNOSPAM.invalid> wrote:
...
> It's also possible to disable history substitution altogether
> with 'set +H'.
>
> I believe this behavior is rather confusing to new users, and
> given that C-r (reverse-search-history) and cursor keys already
> offer a comparable feature, and one likely to fit better with
> user's prior experience at that, my suggestion would be to
> have it disabled by default.

I agree. The ! thing was brought over into bash from (t)csh and it is
pretty universally a bad idea. In fact, the rules for how it is handled
are even more confusing in bash than they are in (t)csh. I can never tell
from looking at it whether or not it is going to try to trigger a history
expansion or not.

I may do as you suggest and disable it globally in my bash shells.

--
People sleep peaceably in their beds at night only because rough
men stand ready to do violence on their behalf.

George Orwell

Kaz Kylheku

unread,
Jun 15, 2023, 8:07:09 PM6/15/23
to
On 2023-06-15, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> In article <u6fvb9$hdk2$1...@dont-email.me>,
> Ivan Shmakov <iv...@siamics.netNOSPAM.invalid> wrote:
> ...
>> It's also possible to disable history substitution altogether
>> with 'set +H'.
>>
>> I believe this behavior is rather confusing to new users, and
>> given that C-r (reverse-search-history) and cursor keys already
>> offer a comparable feature, and one likely to fit better with
>> user's prior experience at that, my suggestion would be to
>> have it disabled by default.
>
> I agree. The ! thing was brought over into bash from (t)csh and it is
> pretty universally a bad idea.

Do you remember There was a period in the 1990's when tcsh was widely
used? It was popular among early Linux users, too. I remember
getting a default login shell as tcsh on some systems, having
to change it with chsh.

It hink this was a spill-over effect of csh use on proprietary Unix
systems; people coming from that finding an equivalent in tcsh.

Bash aping some tcsh features (even not so good ones) probably helped
wean people off that.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazi...@mstdn.ca
0 new messages