`Back quotes` - command line vs. batch file

May 20, 2008
11,798
118
Syracuse, NY, USA
I've been having a lot of trouble with back quotes on the command line not doing what I expect and I keep getting the feeling that they don't work like they have for many years. Maybe I shouldn't have to ask this but ...

The help says

No alias or variable expansion is performed on a parameter enclosed in back quotes. Redirection symbols inside the back quotes are ignored. The back quotes are removed from the command line before the command is executed.

I use this line in several BTMs and it works.

Code:
function tformat `%@instr[0,4,%1]-%@instr[4,2,%1]-%@instr[6,2,%1] %@instr[8,2,%1]:%@instr[10,2,%1]:%@instr[12,2,%1].%@instr[15,3,%1]`

If I use it at a command line, it doesn't work.

Code:
v:\> function tformat `%@instr[0,4,%1]-%@instr[4,2,%1]-%@instr[6,2,%1] %@instr[8,2,%1]:%@instr[10,2,%1]:%@instr[12,2,%1].%@instr[15,3,%1
]`

v:\> function tf*
tformat=-- ::.

And the example from the "Quoting" page in the help doesn't work as that page says.

Code:
v:\> type quotes.bat
@echo off
echo Arg1 = %1
echo Arg2 = %2
echo Arg3 = %3

v:\> set forvar=for

v:\> quotes `Now is the time %forvar` all good
Arg1 = Now
Arg2 = is
Arg3 = the

The help says I should see (and I kinda expect to see)

Code:
Arg1 = Now is the time %forvar
Arg2 = all
Arg3 = good

What's going on?
 
Last edited:

samintz

Scott Mintz
May 20, 2008
1,530
20
Solon, OH, USA
I cannot replicate your issue. It is working correctly for me. Although, when I run your Quotes example, I see:
Code:
$ set forvar=for
$ quotes `Now is the time %forvar` all good
Arg1 = Now is the time for
Arg2 = all
Arg3 = good

So the backquotes got removed and %forvar gets expanded for the echo.
 
May 20, 2008
11,798
118
Syracuse, NY, USA
I cannot replicate your issue. It is working correctly for me. Although, when I run your Quotes example, I see:
Code:
$ set forvar=for
$ quotes `Now is the time %forvar` all good
Arg1 = Now is the time for
Arg2 = all
Arg3 = good

So the backquotes got removed and %forvar gets expanded for the echo.
That's different from mine but still contrary to what the help says and shows.
 
May 20, 2008
11,798
118
Syracuse, NY, USA
If I start TCC with /IIPS, I get the likes of these, which still don't look right.

Code:
v:\> quotes.bat `%o` bar
Arg1 =
Arg2 = bar
Arg3 =

v:\> quotes.bat `oo` bar
Arg1 = oo
Arg2 = bar
Arg3 =

v:\> quotes `Now is the time %forvar` all good

v:\>

And started like that, the back quotes appear in a history recalled command. That's not the case without /IIPS (which also seems wrong).
 
May 20, 2008
11,798
118
Syracuse, NY, USA
I see this difference.

Code:
d:\tc27> which _npids
_npids is a plugin variable (SYSUTILS)

d:\tc27> echo `%_npids`
104

d:\tc27> plugin /u 4utils

d:\tc27> echo `%_npids`
%_npids

d:\tc27>

Scott, do you use 4UTILS?

Also, when it's working right (4UTILS unloaded) back quotes show up in history-recalled commands; not so when 4UTILS is loaded.

I'll look at it but I haven't a clue where to start.
 
May 20, 2008
11,798
118
Syracuse, NY, USA
Hmmm! I had these (far below) in 4UTILS (a recent addition) along with the declarations and DEF-file/PLUGININFO entries to make them work. When I removed them, back quoting on the command line started working correctly. Rex ... any ideas why they'd make a difference?

And the QUOTES.BAT example in the help is in error. When you quotes `Now is the time %forvar`, the variable isn't expanded when the BAT is called, but it is expanded when it's ECHO'd. So Scott's observations are correct.

Code:
INT WINAPI UNKNOWN_CMD (LPWSTR psz)
{
    return 0xFEDCBA98;
}

INT WINAPI PRE_INPUT( LPWSTR psz )
{
    return 0xFEDCBA98;
}

INT WINAPI PRE_EXEC( LPWSTR psz )
{
    return 0xFEDCBA98;
}

INT WINAPI POST_EXEC( LPWSTR psz )
{
    return 0xFEDCBA98;
}
 

Similar threads