LoginSignup
46
35

More than 5 years have passed since last update.

シェルスクリプトで日付と文字列を結合する

Posted at

たとえば、今日が20161031だとして、

article_2016103.txt

という文字列をシェルスクリプトで生成する方法です。

today=$(date "+%Y%m%d")
echo "article_${today}.txt"
# => article_20161031.txt

または、以下のようにも書けるけど、$ の方を使う方が良いらしい。

today=`date "+%Y%m%d"`
echo "article_${today}.txt"
# => article_20161031.txt

おわり。 :thought_balloon:

46
35
1

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
46
35