WAD If it is an error? Diference between aliases and batches

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Greetings. I'm new on this forum, but I'm using 4DOS/4NT/TCC since ... about 17 years :)

Using TCC LE 13.06.77, both 32-bit and 64-bit, Unix/Linux-style paths: off

As far I know, processing of batches and aliases is nearly the same, aliases are de facto simple batches.

Case 1:
Let's define test.btm, containing
@echo off
echo %1 _ %2 _ %3

Let's define an alias:
alias #!=test.btm

And let's check:
#!/usr/bin/sh test.sh

The result is:
/usr/bin/sh _ test.sh _

Great! Works fine, works as expected

Case 2:
To simplify, lets create an alias:
alias #!=`echo %1 _ %2 _ %3`

and check (same, as previous)
#!/usr/bin/sh test.sh

The result is unexpected
/usr _ /bin _ /sh test.sh

.BTM receives 2 params
Why alias receives 3 params (slash is treated as an separator)?

The best regards.

Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
I'm pretty sure that that's deliberate, for the benefit of those users who like to mash options together sans spaces: DEL /S/X/Z *

Argument parsing for batch files has to be compatible with CMD.EXE. Argument parsing for aliases doesn't, since CMD.EXE doesn't have aliases.

Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
You can't use the switch character as a pathname separator, unless you enable Unix style paths. If you want to disable the switch character parsing, either double quote the argument or escape the switch characters.

It appears that alias arg parsing works the same way whether UnixPaths is on or off. (Doubtless a Good Thing.)
I cann't quote nor escape :(

Long post follows, buy it can be valuable for others.

I'm trying to integrate BusyBox (http://intgat.tigress.co.uk/rmy/busybox) into TCL/LE
Line (for example)
comes from thousands Unix/Linux shell scripts.

For now I've got:
Start processing .sh files:
Set .sh=call \somewhere\busybox\bin\BusyBoxRunSh.btm

and the content of BusyBoxRunSh.btm:
Iff "%@Left[2,%@Line[%1,0]]" == "#!" Then
%@Line[%1,0] %$
sh %$

So, if the first two characters of the first line are '#!' I can assume, that the next unix filename is desired parser, and the rest are parameters.
passing #!/usr/bin/bash to BTM works brilliantly:
*Set shellName=%@word["/",%@dec[%@words["/",%1]],%1]
which %shellName>nul:
iff %_? eq 0 Then
%shellName %2$
Echo Unknown command: %shellName
quit 2
%1 is set to the whole /usr/bin/bash - nothing more, nothing less.
And the last word is shell name - "bash" in that case.

So, I've created just another BTM, containing above commands BusyBoxTestSh.btm:
which %@word["/",%@dec[%@words["/",%1]],%1]>nul:
iff %_? eq 0 Then
%@word["/",%@dec[%@words["/",%1]],%1] %2$
Echo Unknown command: %@word["/",%@dec[%@words["/",%1]],%1]
quit 2

and I've pointed it with alias:
alias #!=call \somewhere\busybox\bin\BusyBoxTestSh.btm

It was enough to define busybox' aliases:
alias busybox=\somewhere\busybox\bin\busybox.exe

alias sh=busybox sh

alias ash=busybox ash
alias bash=busybox bash
alias ls=busybox ls
alias vi=busybox vi
... and 90 more aliases :)


Finito. I have got a file test.sh
ls -la

And now I can invoke test.sh from command line.
TCC handles *.sh, recognizes the shell and invokes proper shell.


Everything is ok, but BusyBoxTest.sh is unneeded, it could be replaced with an alias
alias #!=`'%@word["/",%@dec[%@words["/",%1]],%1] %2$`
but alias is receiving different arguments, than BTM

For me - it is not a problem. I've got full integration of BusyBox and TCC/LE. Integration is completed and finished.
I'm working concurrently both on Windows and Linux, and both environments are similar, so I can issue "ls -la" on windows, "dir" on linux, and everything works like a charm.
I wonder - why alias receives other params than .btm ?