#! syntax for xmlsh
On unix, *nix, linux and MacOS systems (all the same but in name only as far as I'm concerned), the #! syntax is a favorite to make an interpreter script execute as a native command.
One may look to the common
Example: myscript
#!/bin/sh echo Hello World
Which is a shell script which can be run as if it were a native executable.
./myscript
Result
Hello World
So how to do the same with xmlsh ?
The Nieve (and I admit I was nieve) is to simply do the same for xmlsh.
All documentation on Unix, Linux and MacOS implies it should work
#!/usr/local/bin/xmlsh xecho <[ "Hello World" ]>
But alas this doesnt work !
Result
./myscript: line 2: syntax error near unexpected token `newline' ./myscript: line 2: `xecho <[ "Hello World" ]>'
What is going on here ? It appears that *nix systems do not like interpreters which are themselves scripts.
I experimented with many cases and found that if the "executable" after the #! is a script instead of a native executable then it simply is ignored. I cannot find this documented anywhere ( reference requested !)
To work around this, however, is easy once you know why it fails.
#!/bin/sh /usr/local/bin/xmlsh echo <[ "Hello World" ]>
This works great because the 'executable" is /bin/sh. It has no performance impact because that is the execuable which would be invoked if /usr/local/bin/xmlsh were run as an interpreter anyway (it starts with #!/bin/sh itself).