Welcome!

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

SignUp Now!

An alias whose action depends on the name used to invoke it

May
12,957
172
I never thought of doing this until today. It works. I must now think of a use for it.

Code:
v:\> alias z*ero `echo %@repeat[0,%@len[%0]]`

v:\> z
0

v:\> ze
00

v:\> zer
000

v:\> zero
0000

A more typical use might be something like this.

Code:
v:\> alias x*y `if %0 == x (echo foo) else (echo bar)`

v:\> x
foo

v:\> xy
bar
 
Unix (and Linux) have used this for many years now. It used to be that "unzip" was just a link to "zip", but that no longer appears to be true. Looking at a new install of Mint, they are separate executables. But "unlz4" is still a link to "lz4". And I'm sure there are many other examples. The only difference being the default action taken, depending on how you call the executable.
 
What does it have to do with links? Windows has links too. The point is that the shell can do this with one alias. I wonder if any Unix/Linux shells can do that.
 
Back
Top