Syntax error when redirecting eval

Would someone please explain why I get a syntax error when I try to redirect the output from an alias for "echo %@eval[%$]"?
Code:
C:\>alias bc
echo %@eval[%$]
 
C:\>bc 2+2
4
 
C:\>bc 2+2 > clip:
TCC: Syntax error "2+2 > clip:"
 
C:\>alias foo=`echo %$`
 
C:\>foo bar+2
bar+2
 
C:\>foo bar+2 > clip:
 
C:\>ver
 
TCC  14.03.59  Windows Vista [Version 6.0.6002]
 
C:\>
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,461
88
Albuquerque, NM
prospero.unm.edu
The > CLIP: is included in the alias arguments %$. Why? Because variable expansion (including aliases) is performed before redirection (so you can use a variable or expression as the filename or device name in a redirection.)

Your original alias will do what you expect if you call it like this:

Code:
( bc 2 + 2 ) > clip:
 
Feb 26, 2013
100
0
Would someone please explain why I get a syntax error when I try to redirect the output from an alias for "echo %@eval[%$]"?
Code:
C:\>alias bc
echo %@eval[%$]
 
C:\>bc 2+2
4
 
C:\>bc 2+2 > clip:
TCC: Syntax error "2+2 > clip:"

The problem is the way you've defined the alias. Using %$ means all of the parameters to the alias are placed inside the @eval brackets. If you press Ctrl-F to expand the aliases on the command line you'll see what's happening, the command line you end up with is

echo %@eval[2+2 > clip:]

and not

echo %@eval[2+2] > clip:

which is what you were hoping for. In this case command grouping will help:

d:\>bc 2+2
4

d:\>(bc 2+2) > clip:

d:\>echo %@clip[0]
4


Dan
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Indded, AFAIK there is no alternative. Same as my nearly identical alias CALC for the same purpose (but I also use @COMMA to make the result more readable).

Note that for some commands, e.g., FOR and GLOBAL, you must also do the same if you want the whole output redirected into a single file, else each iteration is redirected either to its own separate file (if using a file in the CWD) , or it overwrites the single output file (assuming NoClobber=No), so only the last one's result remains... which is noted in their respective HELP pages.

Think of command groups as your friends, not as contortions...
 
Similar threads
Thread starter Title Forum Replies Date
Dan Glynhampton Documentation v15 help: Syntax error in example of @DEC Support 0
krischik Stop Script after Syntax Error. Support 6
M syntax for sftp with publickey Support 3
vefatica IDE external command syntax color? Support 1
Joe Caverly Command Input Syntax Colouring Support 3
C Nested IF syntax — TCC behaving differently to CMD Support 12
rps Documentation Regular expression syntax link broken Support 1
C @diskfree[ ] syntax in 15.00.17 Support 0
T Syntax highlighting in the IDE Support 8
cgunhouse Eventlog Syntax issue Support 8
J syntax problems multiple commands (command & command) Support 4
C CMD's "nested quote" syntax Support 3
T TCTOOLBAR syntax Support 0
S Status line syntax help Support 2
H Double prompt for password with * in FTP syntax Support 3
dcantor FFIND syntax -- is /E"regex" /X supported? Support 2
C extended DIR syntax? Support 7
J Problem with %var:find=replace% syntax Support 5
A syntax colouring Support 0
dcantor Syntax files, and suggestion Support 0
J Problem with peculiar CMD syntax Support 2
C Copy (sys) error Support 3
T Error: This page can’t be displayed Make sure the web address //ieframe.dll/dnserrordiagoff.htm# is correct. Support 8
kb6ojs How to? "Specified Account Already Exists" error installing TCMD v27 Support 12
samintz How to? Abort on error DO loop Support 10
mfarah Fixed The DATE command produces the wrong error message. Support 1
vefatica ON ERROR terminates DO loop. Support 0
C Google intregration error Support 4
C FB intregration error Support 0
gworley rd (Remove Directory) gives interesting error: Support 2
D How to? Skip removing directory (RMDIR) without error message Support 2
Dmitry L. Kobyakov Documentation Error in the Help: the WINDOW command Support 0
M Strange error messages from TCC in FTP copy Support 7
vefatica Error message from TOUCH Support 2
R FIND command error Support 9
fpefpe Python dll error Support 3
D error in help documentation? Support 0
R FOR usage error from TCC but not from CMD Support 16
K_Meinhard Help file error Support 1
X small translation error. Support 0
W pdir returns diff results between tcc and tcmd - one is an error msg Support 5
Dmitry L. Kobyakov From old version: had the setup's error been corrected? Support 6
vefatica Why no error message? Support 2
vefatica ON ERROR and pipes? Support 8
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
Joe Caverly TASKDIALOG Help link error Support 1
J Error "Contents lost before copy" Support 3
vefatica What's causing this error? Support 4
vefatica Error 203? Support 4
C Activation Error. Support 2

Similar threads