Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
スクリプトの現在のディレクトリを MYDIR に格納するこの例では、変数の割り当ての前後に同じディレクトリがエコーされます (cd が呼び出された場合でも)。これにより、コマンド置換はシェルの状態に影響を与えないと思います。それはすべてのコマンド置換に当てはまりますか?
#! /bin/bash echo "$PWD" MYDIR="$( cd "$( dirname "$0" )" && pwd )" echo "$PWD"