ä¸ç¬ã§ãä»æ¥ã®ãã£ã¬ã¯ããªããä½æã»ç§»åã§ããRuby/Bashã¹ã¯ãªãã
ã¡ãã£ã¨ãããã¡ã¤ã«ãä½æã»ä¿åãã¦ããããæãèªåã«ã¨ã£ã¦ã¯ãä»æ¥ã®æ¥ä»ã®ãã£ã¬ã¯ããªãã«ã¾ã¨ãã¦ããã®ãä¸åº¦ãããããã¾ã§ã¯æ¯æ¥æä½æ¥ã§ãä»æ¥ã®æ¥ä»ã®ãã£ã¬ã¯ããªããä½æã»ç§»åãã¦ããã®ã ãã©ããããæ¯åããã®ãé¢åèããã¨ãããã¨ã§ã¹ã¯ãªããã§èªååãããã¡ãªã¿ã«ç°å¢ã¯ruby1.9.2ãbash 3.2.48ã
â»è¿½è¨
ãã³ã¡ã§ãææããã ããéããRuby使ããªãã§Bashã ãã§ã§ãã¾ã...ãªãããããRubyã使ã£ãã®ã...ããã«Rubyããã£ãããã§ã...
æ©è½
ã»ã·ã§ã«ã§ã. todayãã¨å ¥åããã¨ã~/daily/ä»æ¥ã®æ¥ä»ï¼yyyy_mm_ddï¼ããã£ã¬ã¯ããªãä½æã移åãã
å®è£ ã«ããã£ã¦
Rubyã§ãã£ã¬ã¯ããªãä½ãã®ã¯ç°¡åãªã®ã ããç¾å¨ã®ã·ã§ã«ã移åããã®ã«ä¸å·¥å¤«å¿ è¦ã ã£ããRubyã§Dir.chdirããã ãã§ã¯ãç¾å¨ã®ã·ã§ã«ã®ãã£ã¬ã¯ããªã¯ç§»åããªãï¼ããã¾ã§ãrubyã³ãã³ããå®è¡ããã·ã§ã«ã®åããã»ã¹ã¨ãã¦åãããï¼ãããã§ãRubyã¯ãã£ã¬ã¯ããªä½æå¾ã移åã³ãã³ãï¼cd ...ï¼ãæ¨æºåºåã«åãåºãâåãåºãããã³ãã³ããç¾å¨ã®ã·ã§ã«ã§å®è¡ãããã¨ããå¦çã«ããã
æ¨æºåºåã«åãåºãããæååãBashã®ã³ãã³ãã¨ãã¦å®è¡ããã«ã¯ãã³ãã³ãç½®æï¼$()ã``ï¼ãã使ã
ã³ãã³ãç½®æ
ã³ãã³ãç½®æ (command substitution) ãç¨ããã¨ã ã³ãã³ãåãã³ãã³ãã®åºåã§ç½®ãæãããã¾ãã...
http://linuxjm.sourceforge.jp/html/GNU_bash/man1/bash.1.html
ã³ãã³ããç¾å¨ã®ã·ã§ã«ã§å®è¡ããã«ã¯ã.ãsourceãã使ã
. filename [arguments]
source filename [arguments]filename ããã³ãã³ããèªã¿è¾¼ã¿ãç¾å¨ã®ã·ã§ã«ç°å¢ã®ä¸ã§å®è¡ãã¾ãã...
http://linuxjm.sourceforge.jp/html/GNU_bash/man1/bash.1.html
ã³ã¼ããæ¸ã
Ruby
~/script/today.rb
today = Time.now.strftime "%Y_%m_%d" today_dir = File.expand_path("~/daily/#{today}") Dir.mkdir(today_dir) unless File.exist? today_dir puts "cd #{today_dir}"
å®è¡
â»è¿½è¨
ãææããã ããã®ã§ãlsã®è¡¨ç¤ºçµæãæ²è¼ãã¾ãã
ä¾ãã°ãä»æ¥ã®æ¥ä»ã2013å¹´1æ20æ¥ã§ããã®ç¶æ ãã
$ pwd /Users/hidenorimaehara $ ls ~/daily 2013_01_18 2013_01_19
ã·ã§ã«ã§ä»¥ä¸ã®ã³ãã³ããæã¤ã¨
$ . today
â»ã.ãã¯ãsourceãã§ãOK
ä»æ¥ã®æ¥ä»ã®ãã£ã¬ã¯ããªãä½æãã移åã§ããã
$ pwd /Users/hidenorimaehara/daily/2013_01_20 $ ls ../ 2013_01_18 2013_01_19 2013_01_20
ã¨ãªã
Macãªããããããã°ããã£ã¬ã¯ããªç§»åå¾ã«ãã®ãã£ã¬ã¯ããªãFinderãéãã¦ä¾¿å©ã
$ . today
$ open .
çµãã
ã¡ãã£ã¨ããã¹ã¯ãªããã ãã©ãèªåã«ã¨ã£ã¦ã¯çµæ§ä¾¿å©ã ã£ãï¼