A Windows XP help forum. PCbanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » PCbanter forum » Microsoft Windows XP » General XP issues or comments
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

echo "one foo=bar" gives an unexpected result. Why ?



 
 
Thread Tools Display Modes
  #1  
Old March 18th 20, 01:05 PM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default echo "one foo=bar" gives an unexpected result. Why ?

Hello all.

I was thinking about how some characters are not allowed in filenames, and
tried to see if "=" is one of them.
So, I entered, on a commandline, the following: "one foo=bar".

To my surprise the contents of the file became "one =bar"

Can anybody tell me why that "one =bar" result ? (googeling is a bit hard on
it, with the lack of keywords).

Regards,
Rudy Wieser


  #2  
Old March 18th 20, 03:17 PM posted to microsoft.public.windowsxp.general
JJ[_11_]
external usenet poster
 
Posts: 744
Default echo "one foo=bar" gives an unexpected result. Why ?

On Wed, 18 Mar 2020 13:05:49 +0100, R.Wieser wrote:
Hello all.

I was thinking about how some characters are not allowed in filenames, and
tried to see if "=" is one of them.
So, I entered, on a commandline, the following: "one foo=bar".

To my surprise the contents of the file became "one =bar"

Can anybody tell me why that "one =bar" result ? (googeling is a bit hard on
it, with the lack of keywords).

Regards,
Rudy Wieser


Something is wrong with your system.

In my system...

This exact command line:

echo "one foo=bar"

It displays below line without creating any file.

"one foo=bar"

This exact command line:

"one foo=bar"

It displays below line without creating any file.

'"one foo=bar"' is not recognized as an internal or external command,
operable program or batch file.

This exact command line:

one foo=bar

It displays below lines, and creating an empty file named "foo".

'one' is not recognized as an internal or external command,
operable program or batch file.

For the last command line, "foo=bar" file is not created because the "="
character is considered as whitespace if it's not wrapped by double quotes.
  #3  
Old March 18th 20, 04:37 PM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default echo "one foo=bar" gives an unexpected result. Why ?

JJ,

So, I entered, on a commandline, the following: "one foo=bar".


My apologies, as I see that I somehow left the word "echo" out in the body
of the message, and placed the double-quotes wrong in the subjectline. :-(

The full commandline I used is (without the doublequotes ofcourse) "echo one
foo=bar"


This exact command line:

echo "one foo=bar"


:-) /allmost/ the same one.

Regards,
Rudy Wieser


  #4  
Old March 19th 20, 08:25 AM posted to microsoft.public.windowsxp.general
JJ[_11_]
external usenet poster
 
Posts: 744
Default echo "one foo=bar" gives an unexpected result. Why ?

On Wed, 18 Mar 2020 16:37:25 +0100, R.Wieser wrote:
JJ,

So, I entered, on a commandline, the following: "one foo=bar".


My apologies, as I see that I somehow left the word "echo" out in the body
of the message, and placed the double-quotes wrong in the subjectline. :-(

The full commandline I used is (without the doublequotes ofcourse) "echo one
foo=bar"


This exact command line:

echo "one foo=bar"


:-) /allmost/ the same one.

Regards,
Rudy Wieser


Two reasons:
1. The "=" character is treated as delimiters.
2. CMD processes redirection syntax first.

Thus the command line:

echo one foo=bar

CMD recognizes the " foo" syntax as redirection. It stops before the "="
delimiter. Then strips it out from the command line. After the redirection
has been processed, the command line becomes:

echo one =bar

Then that "one =bar" is outputed.

This is similar case when there's a file named "foo=bar" and below command
line is executed.

dir foo=bar

That ends up making DIR listing two files: "foo" and "bar". It's output
would be like this.

Volume in drive E is SOMETHING
Volume Serial Number is 1111-1111

Directory of E:\TEST


Directory of E:\TEST

File Not Found

Notice that it shows two "Directory of..." lines, instead of one.
  #5  
Old March 19th 20, 09:16 AM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default "echo one foo=bar" gives an unexpected result. Why ?

JJ,

(the subjectline has been corrected)

1. The "=" character is treated as delimiters.


Even on the commandline (and not just for batchfile commands) ? I never
knew that. Thanks.

dir foo=bar

That ends up making DIR listing two files: "foo" and "bar".


Which also happens with that "=" replaced by a space ... (in other words,
not something that happens because of that delimiter).

I've just done a (bit less than) quick search for a description of what that
"=" sign actually does/is for on the commandline, but got nowhere fast (a
lot of "how to escape it" or "what does it do in a batchfile" stuff though).

The problem (of sorts) is that I can see what it does, but have no idea (and
can't seem to find) what its purpose is. Currently all I have is a "look
people, this is funny!" application of it.

As my google-fu seems to be weak on this, do you have, by any chance, a link
to a description to what its ment for ?

Regards,
Rudy Wieser


  #6  
Old March 20th 20, 05:09 PM posted to microsoft.public.windowsxp.general
JJ[_11_]
external usenet poster
 
Posts: 744
Default "echo one foo=bar" gives an unexpected result. Why ?

On Thu, 19 Mar 2020 09:16:42 +0100, R.Wieser wrote:

I've just done a (bit less than) quick search for a description of what that
"=" sign actually does/is for on the commandline, but got nowhere fast (a
lot of "how to escape it" or "what does it do in a batchfile" stuff though).

The problem (of sorts) is that I can see what it does, but have no idea (and
can't seem to find) what its purpose is. Currently all I have is a "look
people, this is funny!" application of it.

As my google-fu seems to be weak on this, do you have, by any chance, a link
to a description to what its ment for ?


No idea either. There doesn't seem to be any official documentation about it
or the other semicolon and comma delimiters. Not even example of their
specific usage. The leaked Windows NT source codes may shed some light on
this issue.

CMD is a mysterious (or perhaps, buggy) command interpreter. For example, I
found that the "" character when not used for redirection, is treated as
(no quotes) "?.". And the "" character when not used for redirection, is
treated as (no quotes) "*.". At least for DIR command. e.g.

dir ^
dir ^^
dir ^
dir a^

Would be same as:

dir ?.
dir ??.
dir *.
dir a*.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off






All times are GMT +1. The time now is 12:37 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 PCbanter.
The comments are property of their posters.