4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[シェルスクリプト] ファイル名の操作

Last updated at Posted at 2015-05-09
#!/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
4
4
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?