Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo command with parenthesis in batch file

What function does the open parenthesis serve in this command?

Why is there no closed parenthesis?

>> datatest.csv.TEMP echo(!modified!
like image 743
Steve Richter Avatar asked Mar 05 '23 20:03

Steve Richter


1 Answers

This is the result of a discussion on DosTips about nine years ago.

Your code will redirect the value of !modified! to datatest.csv.TEMP or it will print a blank line in that file if the variable is empty. According to echo /?, the official way to display a blank line is to use echo.. However, if cmd.exe is somehow able to find an executable with no extension called echo (for example, a file in the same directory as the script), that file gets used instead of the regular echo command.

A few alternatives to echo. were considered, including echo\, echo:, echo/ and echo(. echo\ was ruled out in case of a situation where there was a folder called echo that contained a file with the same name as whatever was being echoed. echo/ was ruled out in situations where the string to be displayed started with a ?, because in the case the help was displayed. echo: was ruled out for extremely rare situations where string substitution was being utilized.

Ultimately, echo( was ended up with simply because nobody could find a situation where it didn't work. (Later on, there was some speculation that echo=, echo,, and echo; are all safe to use without weird side effects or edge cases. However, if you are trying to display the literal string /?, the help for echo will be displayed instead.)

The ) is not included because it will get displayed.

like image 105
SomethingDark Avatar answered Mar 23 '23 12:03

SomethingDark