回答:
typeおよびwhichを使用して、特定のコマンドが何であるかbash、およびそれがアプリケーションの場合はそれが存在する場所を判別できます。
$ type type
type is a shell builtin
$ type cd
cd is a shell builtin
$ type ls
ls is aliased to `ls --color=auto'
$ type -P ls
/Users/danielbeck/bin/ls
$ which which
/usr/bin/which
$ which ls
/Users/danielbeck/bin/ls
もちろん、コマンドwhichとtype -Pは、あなたのプログラムでのみ機能しますがPATH、とにかくコマンド名を入力するだけでは他の人を実行することはできません。
OS X(GUI)アプリケーションバンドルがインストールされている場所(openコマンドなど)を判断する簡単な方法を探している場合は、コマンドラインから次の短いAppleScriptを実行できます。
$ osascript -e 'tell application "System Events" to POSIX path of (file of process "Safari" as alias)'
/Applications/Safari.app
これには、問題のプログラム(この例ではSafari)が実行されている必要があります。
これは現在、OSXおよびLinuxでFirefoxアプリケーションディレクトリを見つける方法です。別のアプリケーションに簡単に採用できる必要があります。OSX 10.7、Ubuntu 12.04、Debian Jessieでテスト済み
#!/bin/bash
# Array of possible Firefox application names.
appnames=("IceWeasel" "Firefox")    # "Firefox" "IceWeasel" "etc
#
# Calls lsregister -dump and parses the output for "/Firefox.app", etc.
# Returns the very first result found.
#
function get_osx_ffdir()
{
    # OSX Array of possible lsregister command locations
    # I'm only aware of this one currently
    lsregs=("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister")
    for i in "${lsregs[@]}"; do
        for j in ${appnames[@]}; do
            if [ -f $i ]; then
                # Some logic to parse the output from lsregister
                ffdir=$($i -dump |grep -E "/$j.app$" |cut -d'/' -f2- |head -1)
                ffdir="/$ffdir"
                return 0
            fi
        done
    done
    return 1
}
#
# Uses "which" and "readlink" to locate firefox on Linux, etc
#
function get_ffdir()
{
    for i in "${appnames[@]}"; do
        # Convert "Firefox" to "firefox", etc
        lower=$(echo "$i" |tr '[:upper:]' '[:lower:]')
        # Readlink uses the symlink to find the actual install location
        # will need to be removed for non-symlinked applications
        exec=$(readlink -f "$(which $lower)")
        # Assume the binary's parent folder is the actual application location
        ffdir=$(echo "$exec" |rev |cut -d'/' -f2- |rev)
        if [ -f "$ffdir" ]; then
            return 0
        fi
    done
    return 1
}
echo "Searching for Firefox..."
ffdir=""
if [[ "$OSTYPE" == "darwin"* ]]; then
    # Mac OSX
    get_osx_ffdir
else
    # Linux, etc
    get_ffdir
fi
echo "Found application here: $ffdir"
# TODO: Process failures, i.e. "$ffdir" == "" or "$?" != "0", etc
              type、type -Pしないのか?OSX以外のコードはOS Xで機能しますか?そうでない場合、その理由を説明できますか?はいの場合、なぜ2つのバージョンがあるのですか?
                    /binか/usr/bin、などではなくにインストール/Applications/My3rdPartyApp.appし、バイナリはサブディレクトリに格納されContents/MacOS、それをかなり作りますクロスプラットフォーム技術を使用してアプリケーションの場所を特定するのは困難です(したがっての使用lsregister)さらに悪いことに、OSXディレクトリ構造はバイナリをリソースとは別の場所に配置します。上記のスニペットは、Firefoxのdefaults/prefディレクトリの検索を支援するために書かれました。
                    /usr/bin/firefox実際にはFirefoxのバイナリではないので、出力を使用readlinkして、それが指す場所を特定し、defaluts/prefsそこからディレクトリを見つけます。サイドノートについては、ls -al /usr/bin/* |grep -- '->' |wc -lシンボリックリンクについて:Doing は、そのディレクトリ内の約303個のバイナリを示しています。私のUbuntu構成は実際にはシンボリックリンクです。(それらの約16%)このため、上記のコードは最終的に修正され、バイナリへの正規のパスが見つかるまでシンボリックリンクを再帰的に解決する必要があります。
                    type -P質問に答えるために、私は質問に答えるためにそのコマンドに十分に詳しくありません。おそらく、少し詳しく説明できます。:)
                    type
                    バイナリのパスは$PATH変数で参照されます。
その内容はで確認できますenv。
$PATHで表示できますがenv、echo $PATH冗長ではありません。