Welcome!

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

SignUp Now!

TCC, Bash, and Shebang!

Dec
48
1
I have an interesting puzzle to solve.

We use "Git for Windows" and "Git Extensions" for our source code control.
Those install MinGW64 and Cygwin so that they have a very Linux-like environment available to them.

I want to write some hooks and additional utilities, but I don't want to write them as Bash scripts --- not when I have TCC and Take Command available!

Enter the "Shebang!" line...

For those who are not Linux or Unix jockeys, Bash follows the convention that -- as long as the file is marked executable -- if you have a script that it doesn't directly know how to execute, it looks at the first line of the script. If the first two characters are "#" and "!" it takes the following characters as a path specification to an executable, and passes the pathname of the script to that executable for processing.

(Since programmers have long pronounced the name of exclamation point as "BANG!", years back someone thought it would be cute to pronounce the octothorpe (#) character as "She." Thus, "#! /bin/tch" on the first line of a script is read aloud as "Shebang! Bin Slash T C H.")

Problem is, that convention assumes all scripting languages use "#" as the beginning of a line comment.

Obviously, TCC does not!

Does anyone have a cool syntax trick in TCC / Take Command so that you can have the first line of the .BTM as a shebang-path, and yet not encounter errors once TCC starts processing the file?
 
Hey @forbin,
I have no cool syntax trick to make this work.

I do, however, have some observations.

I use CS-Script (the obsolete .NET Framework version) to run C# code from the command line.

Here's an example, hello.cmd;
Code:
#! cscs
using System;
using System.Windows.Forms;

class Script
{
    static public void Main(string[] args)
    {
        Console.WriteLine("Hello World!" );
        MessageBox.Show("Hello World!");
    }
}

I have saved the above code as hello.cmd

Note that you cannot save it as hello.btm, since EXTPROC or #! only recognize .cmd files.

Running hello.cmd executes the C# code, using the cscs program.

CS-Script also has no problem executing C# code that is stored in a file with a .cmd file extension.

Normally, it would want an extension of .cs or .cscs


Similar results when I want to use #! with a Harbour program.
Code:
#! hbrun.exe
Proc Main
  ? Version()
Return

I have saved the above code as version.cmd

Note that you cannot save it as version.btm, since EXTPROC or #! only recognize .cmd files.

Running version.cmd executes the Harbour code, using the hbrun.exe program.

Harbour also has no problem executing Harbour code that is stored in a file with a .cmd file extension.

Normally, it would want an extension of .prg


When I take the following VBScript code,
Code:
#! cscript.exe //nologo
Function AddOne(theNumber)
  AddOne=theNumber+1
End Function

a = eval("AddOne(10)")
WScript.Echo a
WScript.Echo AddOne(10)
...and save it as addone.cmd, I get the following;
Code:
e:\utils>addone.cmd
Input Error: There is no script engine for file extension ".cm d".
after executing it.

Thus, cscript wants .vbs as the file extension, and does not recognize .cmd as a valid file extension for a VBScript file.

cscript would also have a problem with the first line of the script beginning with #!

Joe
 
I have very modest success after aliasing #! to something innocuous.

Code:
v:\> alias #! echos ^> nul

v:\> alias #!
echos > nul

v:\> bash

vefatica@jj:~$ cat /mnt/v/shebang.btm
#! /mnt/d/tc27/tcc.exe /c v:\shebang.btm
echo foo

vefatica@jj:~$ /mnt/v/shebang.btm
foo

I haven't quite figured out how #! works. One thing for sure is that the shebang line cannot end with CRLF. If the CR is in there, I get the likes of this.

Code:
-bash: ./shebang.btm: /mnt/d/tc27/tcc.exe^M: bad interpreter: No such file or directory
 
A couple notes ...

REM works as an alias for "#!" and seems a bit more elegant than "echo > nul".

You don't need a space after #! if it's followed by a fully-qualified UNIX filename because TCC will see the leading '/' as a parameter separator and still recognize the alias (see example below).

Code:
v:\> alias #!
rem

v:\> bash

vefatica@jj:~$ cat /mnt/v/shebang.btm
#!/mnt/d/tc27/tcc.exe /c v:\shebang.btm
echo cmd  = %0$
echo arg0 = %0
echo arg1 = %1
echo arg2 = %2
echo arg3 = %3
echo arg4 = %4

vefatica@jj:~$ /mnt/v/shebang.btm foo bar
cmd  = v:\shebang.btm /mnt/v/shebang.btm foo bar
arg0 = v:\shebang.btm
arg1 = /mnt/v/shebang.btm
arg2 = foo
arg3 = bar
arg4 =

vefatica@jj:~$
 
We use "Git for Windows" and "Git Extensions" for our source code control.
Those install MinGW64 and Cygwin so that they have a very Linux-like environment available to them.

No, they don't install Cygwin, they install a derivative of it.

I want to write some hooks and additional utilities, but I don't want to write them as Bash scripts
Then write them in plain POSIX shell. There's no reason to not use sh/bash if you have access to it. TCC if for cases where you can not use bash.
But given the TCC developer's attitude, I'm going to switch to powershell even for cases where I could use TCC faster and easier.
 

Similar threads

Back
Top