パスの最初のXディレクトリを削除する方法は?

パスの最初のXディレクトリを削除する方法は?

次のように実行されるコマンドがあります。

./command shortened_path_to_current_directory

の出力はpwd次のとおりです。

/path/to/current/directory

そしてshortened_path_to_current_directory

/current/directory

したがって、パスの最初の2つのディレクトリを削除します。

次のコマンドを実行する方法です。

./command shorten($PWD)

どこからshortenアイテムを削除できますか/path/to

ベストアンサー1

使用パラメータ拡張:

$ echo "/${PWD#*[a-z]*/[a-z]*/}"
/current/directory

望むより:http://mywiki.wooledge.org/BashFAQ/073そしてman bashの「パラメータ拡張」。
また見てくださいhttp://wiki.bash-hackers.org/syntax/pe

おすすめ記事