Fixed Using last argument variable !

rps

Jul 6, 2008
436
6
I clearly don't understand how to use the ! (variable), based on how I read the docs.

" ! returns the last argument of the previous command. The command is retrieved from the history list, so this will not work in a batch file -- it's intended for aliases and command line work."

The following code blocks are being entered at the command line.

What am I doing wrong?

Code:
C:\JPSoft\TCMD17x64\logs>ver

TCC  17.00.53 x64  Windows 7 [Version 6.1.7601]

C:\JPSoft\TCMD17x64\logs>*dir /k /m  tc16* & echo %!
11/16/2014  11:31  70,123  TC16_Nov_2014.log
10/17/2014  2:47  362,052  TC16_Oct_2014.log
!

A second example just in case echo is a special case:
Code:
C:\JPSoft\TCMD17x64\logs>
C:\JPSoft\TCMD17x64\logs>*dir /k /m tc16_nov_2014.log & *copy %! tc16_nov_2014Test.log
11/16/2014  11:30  70,001  TC16_Nov_2014.log
TCC: (Sys) The system cannot find the file specified.
 "C:\JPSoft\TCMD17x64\logs\!"
  0 files copied

As 2 separate commands, no connecting & :

Code:
C:\JPSoft\TCMD17x64\logs>*dir /k /m tc16_nov_2014.log
11/16/2014  11:46          70,938  TC16_Nov_2014.log


C:\JPSoft\TCMD17x64\logs>*dir /k /m %!
TCC: (Sys) The system cannot find the file specified.
"C:\JPSoft\TCMD17x64\logs\!"

Using TCC 16.03.55 x64 yields different and confusing results.
Code:
C:\JPSoft\TCMD16x64\logs>ver

TCC  16.03.55 x64   Windows 7 [Version 6.1.7601]

C:\JPSoft\TCMD16x64\logs>*dir /k /m tc16*
1/17/2014   1:18         224,499  TC16_Jan_2014.log
5/16/2014  23:27           5,280  TC16_May_2014.log
11/16/2014  12:26          25,066  TC16_Nov_2014.log
10/17/2014   2:47          54,604  TC16_Oct_2014.log
9/17/2014  10:53          57,421  TC16_Sep_2014.log

C:\JPSoft\TCMD16x64\logs>*dir /k /m %!
1/17/2014   1:18         224,499  TC16_Jan_2014.log
5/16/2014  23:27           5,280  TC16_May_2014.log
11/16/2014  12:26          25,112  TC16_Nov_2014.log
10/17/2014   2:47          54,604  TC16_Oct_2014.log
9/17/2014  10:53          57,421  TC16_Sep_2014.log

C:\JPSoft\TCMD16x64\logs>*dir /k /m tc16_jan_2014.log & *dir /k /m %!
1/17/2014   1:18         224,499  TC16_Jan_2014.log
TCC: Variable loop "%!"

C:\JPSoft\TCMD16x64\logs>*dir /k /m tc16_nov_2014.log
11/16/2014  12:29  25,345  TC16_Nov_2014.log

C:\JPSoft\TCMD16x64\logs>*dir /k /m tc16_may_2014.log & *dir /k /m %!
 5/16/2014  23:27  5,280  TC16_May_2014.log
11/16/2014  12:30  25,502  TC16_Nov_2014.log

C:\JPSoft\TCMD16x64\logs>ver

TCC  16.03.55 x64  Windows 7 [Version 6.1.7601]

C:\JPSoft\TCMD16x64\logs>*dir /k /m tc16* & echo %!
 1/17/2014  1:18  224,499  TC16_Jan_2014.log
 5/16/2014  23:27  5,280  TC16_May_2014.log
11/16/2014  12:33  25,610  TC16_Nov_2014.log
10/17/2014  2:47  54,604  TC16_Oct_2014.log
 9/17/2014  10:53  57,421  TC16_Sep_2014.log
TCC: Variable loop "%!"

C:\JPSoft\TCMD16x64\logs>*dir /k /m tc16_jan_2014*
 1/17/2014  1:18  224,499  TC16_Jan_2014.log

C:\JPSoft\TCMD16x64\logs>echo %!
tc16_jan_2014*
 
May 20, 2008
11,437
99
Syracuse, NY, USA
It seems to be broken in v17.
In v16 ... The key word here is "history". As you quoted, the value of %! comes from the history. Compound commands go into the history together, just as they were entered. So when I say "echo foo & echo %!" TCC doesn't find "%!" in what it must do next (echo foo) so it puts the (whole) command line in the history and echoes "foo". Now it's time to "echo %!". TCC looks at the last argument in the last command in the history and finds "%!". Thus the variable loop.
I can't figure out what's happening in the last example.
 
May 20, 2008
11,437
99
Syracuse, NY, USA
Maybe my explanation was nonsense. This is going to be affected by your history settings (what to do with duplicates). I discard duplicates and leave the most recent. So below, the 2nd command worked as one might expect. The 3rd command is OK because TCC replaces it with itself in the history; the previous command still ends with "foo". But the 4th command is new ... it's added to the history and now the previous command ends in %! ... hence the loop. (OSLT)
Code:
v:\> echo foo
foo

v:\> echo bar & echo %!
bar
foo

v:\> echo bar & echo %!
bar
foo

v:\> echo foo & echo %!
foo
TCC: Variable loop "%!"
 

rps

Jul 6, 2008
436
6
It seems to be broken in v17.
In v16 ... The key word here is "history". As you quoted, the value of %! comes from the history. Compound commands go into the history together, just as they were entered. So when I say "echo foo & echo %!" TCC doesn't find "%!" in what it must do next (echo foo) so it puts the (whole) command line in the history and echoes "foo". Now it's time to "echo %!". TCC looks at the last argument in the last command in the history and finds "%!". Thus the variable loop.
I can't figure out what's happening in the last example.
Vince,

Thanks for the explanation, I understand for now.

This last example just shows the %! working as you have explained.
Code:
C:\JPSoft\TCMD16x64\logs>*dir /k /m tc16_jan_2014*
1/17/2014  1:18  224,499  TC16_Jan_2014.log

C:\JPSoft\TCMD16x64\logs>echo %!
tc16_jan_2014*

This variable is not as useful to me as I had hoped.

Docs could use some examples and a qualifier/warning about using ` & ` with this variable. Something like: Warning: using this variable when connecting commands with ` & ` will not produce the desired result.

It is still broken in V17.00.53. I have changed the subject to Bug so Rex will notice.
 
Jun 2, 2008
376
2
Newton, MA
I can confirm that it is fixed for

TCC 17.00.54 x64 Windows 7 [Version 6.1.7601]
 
Similar threads
Thread starter Title Forum Replies Date
Jesse Heines Using Regular Expressions with the REN commanc Support 8
R WAD Unusable state when using Chinese characters Support 3
Joe Caverly Using TYPE with non-English text Support 22
L Using TCC.exe through an SSH connection Support 3
Joe Caverly Using @PSHELL from @EVAL Support 8
Jay Sage Command Will Not Run Using Short Name of Path Support 5
Jay Sage Cannot Postion Cursor in Command Line Using Mouse Support 7
MikeBaas Using the debugger Support 2
Joe Caverly Multiple Text Searches at once using FFIND or TPIPE Support 4
Dick Johnson Using the @instr function Support 5
Joe Caverly Using this CMD technique from TCC Support 17
Joe Caverly What version and Windows OS are you using? Support 3
Craig Fitzgerald Problems using tcstart.btm Support 3
R How to? Append files in multiple subfolders using copy? Support 8
M Ctrl-C when using command line history does nothing Support 2
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
C French accents using msgbox Support 4
C "Failed to update the system registry. Please try using REGEDIT" Support 3
x13 Problem listing repository files using DIR http(s)://... Support 8
R Regex using ^ Support 2
cxxl WAD Mouse movement sluggish when using TCC list Support 3
jfalch WAD internal "which" should check for FILEEXIST when using AppPaths entry Support 8
D How to? Scale font in TCC using wheel mouse or other means Support 2
fpefpe Documentation copy/move using /c or /u Support 2
gschizas Fixed Using codepage 65001 (UTF-8) breaks non-ASCII characters Support 8
D How to? Use typed envars using regex. Support 3
epement Using "everything" Support 10
U Installing the Compaq Visual Fortran 6.0 compiler using Take Command Support 8
Alexander WAD The number of files and dirs are multiplied when using multiple wildcards Support 6
T using bottom line for status bar Support 3
A How to? How do you launch TCC/LE using the already-open instance? Support 5
M Incorrect ARGV1 when using linux-style paths Support 4
D How to? Using a custom ini file with TCC from Take Command Support 7
thedave WAD Unable to type various characters using Windows 8's onscreen keyboard Support 7
D Documentation Using "send all input to other tabs" Support 11
Joe Caverly Word Count using TPIPE Support 10
Phileosophos Fixed Option Dialog Hangs when Using Help Support 7
MickeyF problem using COM object in VBScript from v16 x64 TCC but not from v15 32-bit TCC Support 4
S How to? How do I distinguish missing source file from download error when using HTTP? Support 6
Jay Sage Using EVERYTHING Command in TCMD15 Support 5
Charles Dye Odd behavior after using OPTION "Advanced" tab Support 2
T How to? Using FOLDERMONITOR 1 event causes multiple trigger(ing)s Support 8
samintz WAD FILEWRITE using SMOPEN Support 1
ehab aboudaya How to? 2 GUI questions and return HWND using TakeCommandIPC Support 3
R Fixed Using %~dp1 for paths with unavailable drives Support 6
C Using dif. sending addresses with sendmail Support 11
R TC 13 / Using TCDIALOG to exit commands Support 4
epement Video tutorials of using Take Command Support 2
electrotype Error using TCC: "Label not found" Support 6
Phileosophos unzip not using specified path Support 5

Similar threads