Friday, 19 July 2013

Run bash style shell scripts using UnxUtils

In Linux, all the scripts have the following line at the top(known as a shebang)...


So when you run the script, the shell knows to use the program /bin/sh to execute the script.

But this will not work for UnxUtils since there is no /bin directory. You can make one, but then you would have to do that for every partition on your computer, and then put sh.exe in every folder!

The solution is to change the "shebang" so that it looks like this instead...


I find that this allows you to do things like executing the script from the Unix shell in Windows.

Alternatively you can also do this...


But that seems a little non-portable and not so wise.

Unfortunately, however you get it to run, the scripts  then will not work in Linux. If you want your scripts to work in Linux then you must sadly create a bin directory with sh.exe or a bat file pointing to sh.exe in every partition on your hard disk. Then you can indeed use /bin/sh as the path of the shebang.

No comments:

Post a Comment