How to associate /opt/local/bin/bash with .bat files

Clemens Lang cal at macports.org
Tue Jan 28 05:40:15 PST 2014


Hi,

On Tue, Jan 28, 2014 at 07:23:22AM -0600, David Favor wrote:
> Can someone point me to the docs that describe how to associate Mac
> files (like .bat) with the MacPorts version of bash.

Macs (and other Unix systems) don't associate files and their
interpreters based on the filename extension. Only windows uses this
method.

Instead, a method called the "shebang" is used for script files. The
first line in the file you're trying to execute should be in the form of
  #!/path/to/the/binary/which/should/be/used/to/run/this/script

Editing your script and making the first line
  #!/opt/local/bin/bash
should cause MacPorts bash to be used to execute the script. Another
common method is using /usr/bin/env, which in turn uses $PATH to
determine which binary to use:
  #!/usr/bin/env bash

Note that .bat scripts are usually written for windows shell and will
not work with bash on OS X (but you'll probably notice that, if your
script doesn't work).

Further reading: http://en.wikipedia.org/wiki/Shebang_%28Unix%29

-- 
Clemens Lang



More information about the macports-users mailing list