Hack Forums
[Shell] - Batch Characters - Characters that causes errors when tried to echo - - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] - Batch Characters - Characters that causes errors when tried to echo - (/showthread.php?tid=2977548)



- Batch Characters - Characters that causes errors when tried to echo - - DAVEologist - Oct 28, 2012

What are characters that would cause errors when tried echoing?
For example...

Code
echo Hello! I love putting |'s on my thread titles!
pause

It would close automatically because of the pipe, (|) that I put.
So that's only one character. Any other characters?


* - AMDjack - Oct 28, 2012

(Oct 28, 2012 12:43 AM)DAVEologist Wrote:  What are characters that would cause errors when tried echoing?
For example...

Code
echo Hello! I love putting |'s on my thread titles!
pause

It would close automatically because of the pipe, (|) that I put.
So that's only one character. Any other characters?

To get past that put a ^ infront of it IE: ^| and it will work.


* - WOLGA - Oct 28, 2012

He trying to figure out the characters that give the error.

try echoing these

:[]zxcvbnm,.'/@!\#$%^&*()_;{}<>"?+àáâãäåæçèéêëìíîïðñòóôõöøœùúûüýÿþßšžāăąćċčďēěėęğġģħīįiıijķĺļľłńņňőŕřśşťūůűųźżƒdždzțαβγδεζηθικλμνξοπρστυφχψωάέήίόύώϊϋΐΰς΄΅абвгдеёжзийклмнопрстуфхцчшщъыьэюяÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØŒÙÚÛÜÝŸÞߊŽĀĂĄĆĊČĎĒĚĖĘĞĠĢĦĪĮİIIJĶĹĻĽŁŃŅŇŐŔŘŚŞŤŪŮŰŲŹŻƒDžDzȚΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΆΈΉΊΌΎΏΪΫΐΰςАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ¿¡←→↑↓√@§¶†‡|¦–—¤$¢€£¥™©®×÷=±∞ƒºª«»~„"“”^ˇ˘˙¸˛˜′″µ°¹²³♭♪•…¬¯%‰¼½¾⇒⇔●◆*****▲▼☆★♀♂


* - DAVEologist - Oct 28, 2012

(Oct 28, 2012 01:39 AM)Qwertyuiopasdfghjklzxc Wrote:  He trying to figure out the characters that give the error.

try echoing these

:[]zxcvbnm,.'/@!\#$%^&*()_;{}<>"?+àáâãäåæçèéêëìíîïðñòóôõöøœùúûüýÿþßšžāăąćċčďēěėęğġģħīįiıijķĺļľłńņňőŕřśşťūůűųźżƒdždzțαβγδεζηθικλμνξοπρστυφχψωάέήίόύώϊϋΐΰς΄΅абвгдеёжзийклмнопрстуфхцчшщъыьэюяÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØŒÙÚÛÜÝŸÞߊŽĀĂĄĆĊČĎĒĚĖĘĞĠĢĦĪĮİIIJĶĹĻĽŁŃŅŇŐŔŘŚŞŤŪŮŰŲŹŻƒDžDzȚΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΆΈΉΊΌΎΏΪΫΐΰςАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ¿¡←→↑↓√@§¶†‡|¦–—¤$¢€£¥™©®×÷=±∞ƒºª«»~„"“”^ˇ˘˙¸˛˜′″µ°¹²³♭♪•…¬¯%‰¼½¾⇒⇔●◆*****▲▼☆★♀♂

Uhhh... can you please choose non-unicode text? I can't save my Batch file with those.


* - SoulByte - Oct 28, 2012

The characters are these: ^<>%&|

The quote character " can also cause trouble in certain circumstances though not in echo.
The following script would crash:
Code
set abc=hello"world
if "%abc%"=="bla" echo Bla

Parentheses () can also ruin grouping of commands.
This script would also crash as the ) in the echo would end the grouping before the programmer had intended.
Code
if 1==1 (
  echo Hello ) World
  pause>nul
  )

And you can't display ! with delayedexpansion enabled.
Code
setlocal enabledelayedexpansion
echo Hello World!

You can use the escape character ^ to display these special characters (except !).


* - DAVEologist - Oct 28, 2012

(Oct 28, 2012 03:17 AM)SoulByte Wrote:  The characters are these: ^<>%&|

The quote character " can also cause trouble in certain circumstances though not in echo.
The following script would crash:
Code
set abc=hello"world
if "%abc%"=="bla" echo Bla

Parentheses () can also ruin grouping of commands.
This script would also crash as the ) in the echo would end the grouping before the programmer had intended.
Code
if 1==1 (
  echo Hello ) World
  pause>nul
  )

And you can't display ! with delayedexpansion enabled.
Code
setlocal enabledelayedexpansion
echo Hello World!

You can use the escape character ^ to display these special characters (except !).

Cool. Very useful indeed. :)
Thanks for the share!


* - G T X - Oct 28, 2012

(Oct 28, 2012 03:17 AM)SoulByte Wrote:  And you can't display ! with delayedexpansion enabled.

You can use the escape character ^ to display these special characters (except !).

You can display the exclamation mark by escaping it three times.

Code
@echo off
setlocal enabledelayedexpansion
echo Hello World^^^!



* - White Light - Oct 28, 2012

(Oct 28, 2012 01:32 PM)G T X Wrote:  You can display the exclamation mark by escaping it three times.

Code
@echo off
setlocal enabledelayedexpansion
echo Hello World^^^!

I tried that before and it didn't work for me...the only way I could get it to work was to disable setlocal.


* - SIM-1073426 - Oct 28, 2012

(Oct 28, 2012 01:32 PM)G T X Wrote:  You can display the exclamation mark by escaping it three times.

Code
@echo off
setlocal enabledelayedexpansion
echo Hello World^^^!

Actually, you only need to escape it two times.

Code
@echo off
setlocal enabledelayedexpansion
echo Hello World^^!



* - White Light - Oct 28, 2012

(Oct 28, 2012 02:48 PM)Aces. Wrote:  Actually, you only need to escape it two times.

Code
@echo off
setlocal enabledelayedexpansion
echo Hello World^^!

Since the normal functionality of the caret would cause it to protect itself, then it later has the ability to protect the ! then I guess that would be the easiest solution. Any more than 3 would cause extra carets to be displayed, and the third would do nothing (as it doesn't normally show up when it is protecting something).