`-`はCDでのみ使用できますか?

`-`はCDでのみ使用できますか?

cd -現在のディレクトリと以前のディレクトリを切り替えることができます。

以前に他のコマンドの引数として使用されていたようです。 ifがwithと同じ意味であるかどうか-は覚えていません。-cd

私はこれがうまく-いかないことを知りましたls

- CDでのみ使えますか?

ベストアンサー1

-で定義POSIX ユーティリティ構文ガイド標準入力として:

Guideline 13:
For utilities that use operands to represent files to be opened for either 
reading or writing, the '-' operand should be used to mean only standard input 
(or standard output when it is clear from context that an output file is being 
specified) or a file named -.

ファイルを読み書きするユーティリティの定義を表示できます。cdはこれらのユーティリティに属していないため、-CDではこの指示に従わないでください。

また、POSIX は-独自の意味を定義します。CD:

-
    When a <hyphen> is used as the operand, this shall be equivalent to the 
    command:

    cd "$OLDPWD" && pwd

    which changes to the previous working directory and then writes its name.

おすすめ記事