Bash 파일명에서 확장자 제외

Jmnote (토론 | 기여)님의 2023년 9월 28일 (목) 17:27 판 (→‎같이 보기)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

Bash 파일명에서 확장자 제외
리눅스 확장자 제외한 파일명 추출

2 basename 할용[ | ]

basename 파일명 .확장자
basename -s .확장자 파일명
basename helloworld.txt .txt
MYFILE=hello.txt
basename $MYFILE .txt
MYFILE=hello.txt.gz
basename $MYFILE .gz
root@wsl:/etc# basename issue.net
issue.net
root@wsl:/etc# basename issue.net .net
issue

3 sed 활용[ | ]

root@wsl:/etc# ls issue.net
issue.net
root@wsl:/etc# FILENAME=$(ls issue.net | sed 's|\.[^.]\+||g')
root@wsl:/etc# echo $FILENAME
issue
root@wsl:/etc# echo issue.net
issue.net
root@wsl:/etc# FILENAME=$(echo issue.net | sed 's|\.[^.]\+||g')
root@wsl:/etc# echo $FILENAME
issue

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}