![경로의 첫 번째 X 디렉터리를 삭제하는 방법은 무엇입니까?](https://linux55.com/image/218044/%EA%B2%BD%EB%A1%9C%EC%9D%98%20%EC%B2%AB%20%EB%B2%88%EC%A7%B8%20X%20%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%EB%A5%BC%20%EC%82%AD%EC%A0%9C%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
다음과 같이 실행되는 명령이 있습니다.
./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