Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Issue with CD_LEAVE Alias

Jun
539
3
I don't understand what is happening here.

TCC(27.01.23): C:\>alias cd_leave
echo `%1=`%1 & set oldcwd=%1 & echo oldcwd=%oldcwd

TCC(27.01.23): C:\>cd temp
%1=C:\
oldcwd=C:\ C:\temp

TCC(27.01.23): C:\temp>

It is acting as though I had written "set oldcwd=%1 %2" as the middle command of the three. If I change the alias to

echo `%1=`%1, `%2=`%2 & set oldcwd=%1 & echo oldcwd=%oldcwd

then things work.

TCC(27.01.23): C:\>alias cd_leave
echo `%1=`%1, `%2=`%2 & set oldcwd=%1 & echo oldcwd=%oldcwd

TCC(27.01.23): C:\>temp\
%1=C:\, %2=C:\temp
oldcwd=C:\

TCC(27.01.23): C:\temp>
 
Code:
CD_Leave - TCC will execute this alias when it is about to change the current directory.
TCC will pass the name of the current directory (%1) and the name of the new directory (%2).

Aliases have always acted that way. Any parameters given but not referred to in the alias are added to the end at execution time. So in your example,

Code:
echo `%1=`%1 & set oldcwd=%1 & echo oldcwd=%oldcwd

acts like

Code:
echo `%1=`%1 & set oldcwd=%1 & echo oldcwd=%oldcwd %2
 
Code:
v:\> alias ttt
echo %1 & echo %1

v:\> ttt abc def
abc
abc def
 
Ah yes. I thought of that, but it looked as though the %2 was getting added to the set command in the middle. If I change the alias to

echo `%1=`%1 & set oldcwd=%1 & echo oldcwd=%oldcwd & echo Last command

then I see that oldcwd does get defined correctly.

%1=C:\
oldcwd=C:\
Last command C:\temp

The more serious issues are with the cd_enter alias. I hope that there is a simple explanation (and solution).
 

Similar threads

Back
Top