Proposal to set a standard ECHO charactr to show blank lines

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Aacini
Expert
Posts: 1887
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Proposal to set a standard ECHO charactr to show blank lines

#1 Post by Aacini » 08 Dec 2011 22:41

To display a blank line in a Batch file, or a line with the value of a variable that may be empty, we used to include certain characters in ECHO command: ECHO., ECHO/, ECHO(, etc. I think it would be a good idea to agree in a standard character that be both effective and clear for everybody, even the novice Batch programmer, and that have no special cases.

(The following is a brief description for those that don't know the subject):

Some time ago someone at Microsoft have the unfortunate idea to use the dot in a published example of this use, so the use of ECHO. to display blank lines is widely known. The problem with this character is that the dot is used in a standard way by the command interpreter to separate the filename and the extension so, for example, ECHO.EXE or ECHO.BAT commands may confuse the novice and indeed may produce different results depending on OS version, in particular if original MS-DOS command.com (not cmd.exe) is used.

Although any unused special character may be used for this purpose, certain characters are better than others. The best choice would be a character that is NOT used for other purposes in a Batch file, or that is used for a similar purpose. I used to include a slash to display blank lines: ECHO/ and variables: ECHO/%VAR% based on the idea that the slash is the standard character used in commands for command options. The problem happen when the variable value is a single question-mark character: SET VAR=? because in this case ECHO/%VAR% command will show the echo help description (as jeb appropriately indicate).

jeb used to include a left parentheses: ECHO(; the problem is that this character IS used with other important purpose in Batch files and an unclosed left parentheses may confuse not just a human being, but also an application developed to check the balance of parentheses in a Batch file (unless ECHO( is managed as special case). Note that unbalanced parentheses is a common mistake of novice programmers, and that you just confuse they even more if you try to explain them why this line:

Code: Select all

for /L %%i in (1,1,%limit%) do (echo(!Array%%i!))


Is WRONG, but the following one is RIGHT!

Code: Select all

for /L %%i in (1,1,%limit%) do (echo(!Array%%i!)


I looked then at the Batch standard delimiter characters besides the space: comma, semicolon and equal-sign. Of these three, I choose the equal-sign not just because it is the most visually appealing, but also because ECHO=Any message command resembles the standard command to show a message with no advance to new line: SET /P =Any message < NUL.

In conclusion, I propose the equal-sign as the standard character to display blank lines and empty variables in ECHO command. What do you think?

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Proposal to set a standard ECHO charactr to show blank l

#2 Post by dbenham » 08 Dec 2011 23:30

I like it :!: :D

jeb acknowledged that echo= seems to work in this thread, but then when he listed all his exhaustive testing that failed in a later post, he never seemed to have tested that option.

I tested using jeb's tests, and can't find any situation that fails. Unless jeb (or anyone) can find a situation that fails, I think you have a winner :!:

I've been using echo( myself, but I agree it is visually confusing, and I would prefer echo=


Dave Benham

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Proposal to set a standard ECHO charactr to show blank l

#3 Post by alan_b » 09 Dec 2011 03:56

Many thanks - now happily using ECHO=

Alan

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Proposal to set a standard ECHO charactr to show blank l

#4 Post by dbenham » 09 Dec 2011 12:59

aGerman points out that echo=/? displays help message: viewtopic.php?p=11958#p11958
I'll be sticking with echo( after all. :(

Dave Benham

jeb
Expert
Posts: 1043
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Proposal to set a standard ECHO charactr to show blank l

#5 Post by jeb » 09 Dec 2011 16:33

@Aacini
As aGerman pointed ECHO= doesn't work.

But you point me to re-test my old results
and I was suprised to see unexpected behaviour with echo+,echo[ and echo] :D

I will try to show my test suite in the main thread and the new "results".

jeb

Aacini
Expert
Posts: 1887
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Proposal to set a standard ECHO charactr to show blank l

#6 Post by Aacini » 09 Dec 2011 20:16

I thought I had a winner... :cry:
So we must continue using ECHO( until a better character be found...

However, I still don't like ECHO(, so I'll use dbenham macro method: SET ECHO=ECHO( and then use %ECHO% instead. :wink:

©opy[it]®ight
Posts: 60
Joined: 17 Mar 2012 09:59

Re: Proposal to set a standard ECHO charactr to show blank l

#7 Post by ©opy[it]®ight » 23 Mar 2012 18:54

Interesting read. Hopefully you people don't mind me for using ECHO. :oops:

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Proposal to set a standard ECHO charactr to show blank l

#8 Post by Ed Dyreen » 23 Mar 2012 19:19

'
Not at all, outside functions I use echo. by default too, but inside I use %echon_%

Code: Select all

set "echo_=<nul set/p="
set "echon_=echo("

Judago
Posts: 15
Joined: 04 Nov 2011 07:59

Re: Proposal to set a standard ECHO charactr to show blank l

#9 Post by Judago » 23 Mar 2012 21:16

Code: Select all

set "echo_=<nul set/p="


It's such a pity that even this has an issue.

Code: Select all

set "echo_=<nul set/p="
%echo_%=

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Proposal to set a standard ECHO charactr to show blank l

#10 Post by aGerman » 24 Mar 2012 14:03

Code: Select all

for /f %%a in ('"prompt $H$S &echo on &for %%b in (1) do rem"') do set "echo_=<nul set/p=.%%a"
%echo_%=

... but this doesn't solve all issues! If you redirect that output into a file you will find the dot and the back-space character as well. It's only a suitable way for displaying characters like = or leading white spaces (Win7).

Regards
aGerman

Aacini
Expert
Posts: 1887
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Proposal to set a standard ECHO charactr to show blank l

#11 Post by Aacini » 24 Mar 2012 21:20

@aGerman: you may get the same result with the simpler:

Code: Select all

for /f %%a in ('echo prompt $H ^| cmd') do set "echo_=<nul set/p=.%%a"
%echo_%=

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Proposal to set a standard ECHO charactr to show blank l

#12 Post by aGerman » 25 Mar 2012 08:08

Well the reason why I prefer jeb's method is that your method creates a new cmd process which slows it down and is IMHO unnecessary.
But you're right that prompt $H is sufficient since it deals out a combination of <BS><Space><BS>.

Regards
aGerman

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Proposal to set a standard ECHO charactr to show blank l

#13 Post by dbenham » 25 Mar 2012 20:28

And both methods are only capturing the leading <BS> since the default DELIMS includes <space>.

If text is always starting at the beginning of a line (a big if), then the leading character is not necessary: set/p=<BS><space>.... works just fine.

But it is probably better to include a character such as the dot like you did, just in case the "echo" is starting in the middle of the line.


Dave Benham

Post Reply