#!/bin/sh
test_path="/usr/local/etc/apache/httpd.conf"
# ファイル名 (拡張子付き)
basename $test_path # httpd.conf
echo ${test_path##*/} # httpd.conf
# ファイル名 (拡張子無し)
basename $test_path '.conf' # httpd
echo ${${test_path##*/}%.*} # httpd #この書き方(変数をネストする書き方)はzshのみ。
# 拡張子
echo ${test_path##*.} # conf
# 親フォルダ
dirname $test_path # /usr/local/etc/apache
echo ${test_path%/*} # /usr/local/etc/apache
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme