
ではbash 4.4.12
、次のようにhelp cd
述べています。
Options: -L force symbolic links to be followed: resolve symbolic links in DIR after processing instances of `..' -P use the physical directory structure without following symbolic links: resolve symbolic links in DIR before processing instances of `..' -e if the -P option is supplied, and the current working directory cannot be determined successfully, exit with a non-zero status -@ on systems that support it, present a file with extended attributes as a directory containing the file attributes
これらの言葉を理解するのが難しく、Google で検索しても何も出てきません。
cd -P
が よりも好まれる場合の例は何ですかcd
?cd -L
標準とどう違うのですかcd
?- 作業ディレクトリを正常に特定できないのはなぜでしょうか?
- の使用例は何ですか
-@
?
答え1
のBash マニュアルもう少し詳しく説明します。
cd -P
最終的に「実際の」パスが得られることを保証します。$ cd /tmp $ mkdir -p a/b $ ln -s a/b b $ cd b $ pwd /tmp/b $ cd -P ../b $ pwd /tmp/a/b
を使用すると、から
-P
へのシンボリックリンクが逆参照されます。とのやり取りは、通常、ディスク上のパスをチェックするのではなく、以前のパス コンポーネントがある場合はそれを削除することによって処理されます。シンボリックリンクを多数使用すると、非常に混乱する可能性があります。b
a/b
..
..
cd -L
デフォルトと同等ですcd
。現在の作業ディレクトリは削除されている場合は判別できません。
$ cd /tmp $ mkdir -p c/d $ cd c/d $ rmdir ../d ../../c $ cd ..; echo $? cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory 0
v.
$ cd -Pe ..; echo $? cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory 1
これについてはよくわかりません (どのように表示されるかは想像できますが、Bash では単に「
cd
:-@
: 無効なオプション」と表示されます。これは現在 Solaris でのみ使用可能で、 が必要であるという印象を受けますO_XATTR
)。