LoginSignup
2
1

More than 5 years have passed since last update.

今日の日付に合わせて yyyy-mm/yyyy-mm-dd.md を作成するシェルスクリプト

Posted at

変数展開でトリミングできるんですね!という話。

#!/bin/bash
readonly ROOT=$(realpath $(dirname $0))

fileName=$(date +"%Y-%m-%d").md
dirName=${fileName%-[0-9]*.md}

filePath="$ROOT/$dirName/$fileName"
if [ ! -e "$ROOT/$dirName" ]; then
    mkdir "$ROOT/$dirName"
fi
touch $filePath
2
1
2

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
2
1