Alias expansion and switch character

May 30, 2008
235
2
Using build 151.

Should alias expansion cause an extra space to be inserted before switch (/) characters used in the alias parameters given when invoking the alias?

It seems to do that with this alias:

alias cpfrom=*copy /G ftp:%1 %2

c:\> cpfrom putget/idoc.zip

After expansion with Ctrl-F:

c:\> copy /G ftp:putget /idoc.zip

Note the extra space after "putget".

Needless to say, this causes the command to fail.
A simple work-around is to use `cpfrom "putget/idoc.zip"` instead.

Defining the alias as

alias cpfrom=*copy /G "ftp:%1" %2

does not help.

Is this behaviour deliberate or might it be a bug in the alias expansion handling?

Might there be a way to define the alias so that `cpfrom putget/idoc.zip` works "as expected"?

--
Niklas Bäckman
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,425
85
Albuquerque, NM
prospero.unm.edu
Should alias expansion cause an extra space to be inserted before switch (/) characters used in the alias parameters given when invoking the alias?

It seems to do that with this alias:

alias cpfrom=*copy /G ftp:%1 %2

c:\> cpfrom putget/idoc.zip

After expansion with Ctrl-F:

c:\> copy /G ftp:putget /idoc.zip

Note the extra space after "putget".

The "extra" space is in your alias definition, between the %1 and the %2. If you don't want PUTGET and /IDOC.ZIP to be treated as two separate parameters, then quoting the entire string is the correct way to do that.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
nikbackm wrote:
| Using build 151.
|
| Should alias expansion cause an extra space to be inserted before
| switch (/) characters used in the alias parameters given when
| invoking the alias?
|
| It seems to do that with this alias:
|
| alias cpfrom=*copy /G ftp:%1 %2

I presume you did not use the above command as displayed when defining the
alias CPFROM, as it would have expanded %1 and %2 during definition,
resulting in


> which cpfrom
cpfrom is an alias: *copy /G ftp:

With this definition of CPFROM, I get different result:


>cpfrom putget/idoc.zip [ctrl-F]
>copy /G ftp: putget/idoc.zip

Note the extra space BEFORE "putget". This is exactly what I would expect.

I then tried

alias cpfrom=`*copy /G ftp:%1 %2`

Now entering


>cpfrom putget/idoc.zip [ctrl-F]
>copy /G ftp:putget /idoc.zip

as in the OP.

Entering


>cpfrom "putget/idoc.zip" [ctrl-F]
>copy /G ftp:"putget/idoc.zip"

as expected, but it's wrong syntax!

The problem is that / is parsed as a parameter separator. I have not come up
with a variant alias to perform according to the perceived intent of the OP.

Another problem is that if COPY is an alias, the alias expansion replaces
*COPY with COPY, thus executing the command will use the value of the alias
COPY, not the internal command COPY. This is definitely a parser error, or
at least a limitation of the alias expansion logic triggered by ctrl-F.

What I don't know is what the command actually built by the parser without
the expansion actually looks like.
 
Similar threads
Thread starter Title Forum Replies Date
nickles Alias expansion Support 7
Stefano Piccardi setdos /x-4 affects alias expansion v10 vs v13 Support 8
mikea TCC: Disabling alias expansion with '*' Support 1
Jay Sage Issue with CD_ENTER Alias Support 37
Jay Sage Issue with CD_LEAVE Alias Support 3
Jay Sage WAD Failure of Alias Command with /Z Option Support 14
R @select inside alias gives different (insanely small) window Support 7
kb6ojs ALIAS with multiple commands? Support 9
vefatica Can I alias @@Ctrl-Shift-Alt-u? Support 4
D Alias with setdos no longer works Support 21
vefatica TPIPE in an alias? Support 2
Peter Murschall TCC V26.01.3x Debugging has problems with Alias /R Support 1
Peter Murschall CMDebug 26.01.37 has problems with Alias Support 21
samintz How to? Alias or prompt? Support 1
MickeyF expand alias in cmdline with Ctrl-F in TCC Support 21
Jay Sage Directory Alias Access to FTP Servers Support 2
rps How to? Shralias and producing history.sav, alias.sav .. Support 6
J Alias @@F5 hotkey Support 2
vefatica alias.sav not accurate Support 8
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
N multiple command alias and redirection Support 0
vefatica SETLOCAL ... ALIAS ... pipes Support 2
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
rps How to? Alias/Command line use of *log on/off Support 2
MickeyF alias terminating before it should Support 3
JohnQSmith ALIAS /R in TCSTART.BTM Support 9
D Alias in batch file Support 3
vefatica Can't execute @ALIAS[...] Support 5
E How to? Load Alias File on Startup Support 3
I Windows 10 console does not allow alt-F4 alias to complete Support 1
MickeyF create an alias with optional parameter Support 4
T scrput `` in alias or function Support 2
vefatica Alias works differenltly v16 vs. v17 Support 13
B Alias with multi line definitions not assigned Support 6
jbanaszczyk Alias with space in the name Support 3
jbanaszczyk Alias for internal command Support 8
D Clear alias parameters Support 7
T Fixed multi-line alias issue Support 13
keithg1964 WAD 16.0027 Alias /rz bug Support 8
R In addition to ALIAS /Z and FUNCTION /Z, HISTORY /Z? Support 1
tmaynard How to? Control-U alias for Escape (command line editing) Support 5
C Alias ListEmptyFldrs=??? Support 4
M How to? Put logic into an alias... Support 6
G How to? v15: Can't alias Alt-Z Support 7
nikbackm v15: Problem with ALIAS in command group Support 10
vefatica WAD DO i=1 TO %# in an alias? Support 9
cgunhouse Directory Alias Issue Support 7
C CMD window size and post_exec alias ? Support 6
deleyd How to? Alias in TCMD.INI file? Support 2
M How to? Run a command (alias, actually) on a "timed" basis... Support 13

Similar threads