Search code examples
macosbashenvironment-variableswine

Executing wine != executing `which wine`


I have a "funny" problem where running wine in two respective ways results in:

$> wine --version
/Applications/Wine.app/Contents/Resources/bin/wine: No such file or directory

$> `which wine` --version
wine-1.8

I had a wine installation in Applications a long time ago, but not anymore. The current (working) installation is installed via Homebrew. I can neither find any environment variable messing up my path or likewise.

Any suggestions what may cause this annoyance?


Solution

  • Use the bash type builtin or command -v, not which, to determine what your shell will actually do when a command is run. (Don't use the output of any of these to form another command in the way your question suggests; the code given in your question would fail if the output for which contained a directory name with a space, a glob literal prone to expansion, or similar).

    which tells you what's first in your PATH, but since it's an external tool rather than part of the shell, it's unaware of behaviors that depend on the shell's state. (Think aliases, functions, hashed lookups, etc).

    If you have an alias, you may see something like the following:

    $ type wine
    wine is aliased to `/Applications/Wine.app/Contents/Resources/bin/wine'
    $ command -v wine
    alias wine='/Applications/Wine.app/Contents/Resources/bin/wine'
    

    ...or, for a function:

    $ type wine
    wine is a function
    wine ()
    {
        /Applications/Wine.app/Contents/Resources/bin/wine "$@"
    }
    $ command -v wine
    wine