è¦ãã¦ããã¨ããã¾ã«ä¾¿å©ãããããªã"bash"ã®ã³ãã³ãå±¥æ´ã®å±éã«é¢ããæããä¾ã交ããªããã¾ã¨ãã¦ã¿ã¾ããã
æå¾ã«ãæ¸ãã¾ããããä»ã«ãããããããã¾ãã®ã§ãè²ã
試ãã¦ã¿ã¦ãã ããã
ç´åã«å®è¡ããã³ãã³ããå®è¡
"!!"ã³ãã³ãã§ã1ã¤åã«å®è¡ããã³ãã³ããå度å®è¡ã§ãã¾ãã
$ ls -l åè¨ 0 -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:20 test $ !! ls -l åè¨ 0 -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:20 test
nååã«å®è¡ããã³ãã³ããå®è¡
"!-n"ã³ãã³ãã§ãnååã«å®è¡ããã³ãã³ããå度å®è¡ã§ãã¾ãã
ä¾ãã°ã以ä¸ã®ä¾ã§ã¯ã"!-2"ã¨ããã¨ã2ååã«å®è¡ããã³ãã³ããå®è¡ãã¦ãã¾ãã
$ ls test $ ls -l åè¨ 0 -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:20 test $ !-2 ls test
ä¸ã§ç´¹ä»ãã"!!"ã³ãã³ãã¯ã"!-1"ã³ãã³ãã¨åçã¨ãããã¨ã«ãªãã¾ãã
ç¹å®ã®æååã§å§ã¾ãã³ãã³ãã®ãã¡ãä¸çªè¿ãã³ãã³ããå®è¡
"!string"ã§ãstringã§å§ã¾ãã³ãã³ãã®ãã¡ãéå»ã«ä¸çªæè¿å®è¡ããããã®ãå度å®è¡ãã¾ãã
以ä¸ã®ä¾ã§ã¯ã"!p"ã¨ãããã¨ã§ãpããå§ã¾ãç´è¿ã§å®è¡ãããã³ãã³ã(pwd)ãå®è¡ãã¦ãã¾ãã
$ pwd /home/rx7/tmp $ ls test $ !p pwd /home/rx7/tmp
ç¹å®ã®æååãå«ãéå»ã®ã³ãã³ãã§ãä¸çªè¿ãã³ãã³ããå®è¡
1ã¤ä¸ã®ã¨ãããä¼¼ã¦ãã¾ããã
"!?string"ã§ã¯ãstringãå«ãã³ãã³ãã®ãã¡ãéå»ã«ä¸çªæè¿å®è¡ããããã®ãå度å®è¡ãã¾ãã
1ã¤ä¸ã¨ã®éãã¯ããã®å ´åã¯ã³ãã³ããå¼æ°ããªãã·ã§ã³ãåºå¥ããªãç¹ã§ãã
$ ls -l åè¨ 0 -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:20 test $ echo ls ls $ !?ls echo ls ls
å±¥æ´ããå®è¡ãããã³ãã³ãã®ç¢ºèª
éå»ã«å®è¡ãããã³ãã³ãã®å±¥æ´ãããåå©ç¨ããå½¢ã§ã³ãã³ããå®è¡ã§ãããã¨ã¯ä¾¿å©ã§ãããæ
éã«å®è¡ãããå ´åãªã©ã¯ãå®è¡å
容ã確èªãããå ´åããããã¨æãã¾ãã
ãããã£ãã¨ãã¯ã":p"ãä»ãããã¨ã§ãå®è¡ãããã³ãã³ãã表示ããã"ã ã"ã§ãä½ã®ã³ãã³ããå®è¡ãããã®ãã確èªãããã¨ãåºæ¥ã¾ãã
$ ls -l åè¨ 0 -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:20 test $ !!:p ls -l
ç´åã®ã³ãã³ãã®(æå¾ã®)å¼æ°ãåå©ç¨
"!$"ã使ããã¨ã§ã以ä¸ã®ããã«ç´åã«å®è¡ããã³ãã³ãã®æå¾ã®å¼æ°ãå©ç¨ãããã¨ãã§ãã¾ãã
$ pwd /home/rx7/tmp $ mkdir hoge $ cd !$ cd hoge $ pwd /home/rx7/tmp/hoge
ç´åã®ã³ãã³ãã®å ¨ã¦ã®å¼æ°ãåå©ç¨
"!*"ã使ããã¨ã§ã以ä¸ã®ããã«ç´åã«å®è¡ããã³ãã³ãã®å ¨ã¦ã®å¼æ°ãå©ç¨ãããã¨ãã§ãã¾ãã
$ touch foo bar $ ls -l !* ls -l foo bar -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:25 bar -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:25 foo
æååã®ä¸é¨ãå¤æ´ãã¦å®è¡
"^before^after"ã®å½¢å¼ã§å®è¡ãããã¨ã§ãç´åã®ã³ãã³ãã®ç¹å®ã®æååãç½®æãã¦å®è¡ãããã¨ãã§ãã¾ãã
ä¾ãã°ã以ä¸ã®ä¾ã§ã¯ãç´åã®ã³ãã³ãã®(å¼æ°ã§ãã)"hoge"ã"fuga"ã«ç½®æãã¦å®è¡ãè¡ã£ã¦ãã¾ãã
$ ls -l åè¨ 0 $ touch hoge $ ^hoge^fuga touch fuga $ ls -l åè¨ 0 -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:28 fuga -rw-rw-r-- 1 rx7 rx7 0 2009-02-26 02:28 hoge
ããã¯ã"!!:s/hoge/fuga/"ã§ã代æ¿å¯è½ã§ãã
ã¤ã¾ãå¿ç¨ããã¨ãç´åã®ã³ãã³ã以å¤ã§ãç½®æãã¦å®è¡ã§ãã¾ãã
ãã®ä»ãåè
ãhttp://www.linux.or.jp/JM/html/GNU_bash/man1/bash.1.htmlãããªãã¡ã¬ã³ã¹ã¨ãªã£ã¦ãããã¨ã¦ãåèã«ãªãã¾ãã
以ä¸ã«ãä»åã®è©±é¡ã«é¢é£ããä¸é¨å(å±¥æ´ã®å±é)ã転è¼ããã¦ããã ãã¾ãã
ã¤ãã³ãæ示å (Event Designator)
ã¤ãã³ãæ示åã¯ãå±¥æ´ãªã¹ãä¸ã®ã³ãã³ãã©ã¤ã³ã¨ã³ããªãåç §ãããã®ã§ãã ! å±¥æ´ç½®æãéå§ãã¾ãããã ãããã©ã³ã¯æåãæ¹è¡æåã=, ( ã®ãããããå¾ã«ç¶ãå ´åã¯é¤ãã¾ãã !n n è¡ç®ã®ã³ãã³ãã©ã¤ã³ãåç §ãã¾ãã !-n ç¾å¨ãã n è¡åã®ã³ãã³ãã©ã¤ã³ãåç §ãã¾ãã !! 1 è¡åã®ã³ãã³ãã©ã¤ã³ãåç §ãã¾ãã`!-1' ã¨å義ã§ãã !string string ã§å§ã¾ãã³ãã³ãã®ãã¡ãä¸çªç¾å¨ã«è¿ãã¨ããã§å®è¡ãããã®ãåç §ãã¾ãã !?string[?] string ãå«ãã³ãã³ãã®ãã¡ãä¸çªç¾å¨ã«è¿ãã¨ããã§å®è¡ãããã®ãåç §ãã¾ãã string ã®ç´å¾ãæ¹è¡æåãªãã°ãæå¾ã® ? ã¯çç¥ãã¦ãæ§ãã¾ããã ^string1^string2^ ç°¡æç½®æã string1 ã string2 ã«ç½®æãã¦ç´åã®ã³ãã³ããç¹°ãè¿ãã¾ãã ``!!:s/string1/string2/'' ã¨å義ã§ã (å¾è¿°ã®ä¿®é£¾åãåç §)ã !# ä»ã¾ã§ã®ã¨ããã¾ã§ã«æã¡è¾¼ãã ã³ãã³ãã©ã¤ã³å ¨ä½ã§ãã
åèªæ示å (Word Designators)
åèªæ示å (word designator) ã¯ãã¤ãã³ããã欲ããåèªãé¸ã¶æã«ç¨ãããã¾ããã¤ãã³ãæå®ã¨åèªæ示åã®ã»ãã¬ã¼ã¿ã«ã¯ : ãç¨ãã¾ããåèªæ示åã ^, $, *, -, % ã®ããããã§å§ã¾ãå ´åã«ã¯ããã®ã»ãã¬ã¼ã¿ã¯çç¥ã§ãã¾ããåèªã«ã¯è¡ã®å é ããçªå·ãæ¯ããã¾ããå é ã®åèªã 0 çªç®ã«ãªãã¾ããåèªã¯ç¾å¨ã®è¡ã«ãç©ºç½ 1 ã¤ã§åºåããã¦æ¿å ¥ããã¾ãã 0 (ã¼ã) 0 çªç®ã®åèªããã®ã·ã§ã«ã«ã¨ã£ã¦ã¯ãããã¯ã³ãã³ãã表ãåèªã§ãã n n çªç®ã®åèªã ^ æåã®å¼ãæ°ãã¤ã¾ã 1 çªç®ã®åèªã§ãã $ æå¾ã®å¼ãæ°ã % `?string?' æ¤ç´¢ã«ããããããä¸çªç¾å¨ã«è¿ãåèªã x-y åèªã®ç¯å²ã`0-y' ã®çç¥å½¢ã¨ã㦠`-y' ã使ãã¾ãã * 0 çªç®ãé¤ãå ¨ã¦ã®åèªããã㯠`1-$' ã®å¥è¡¨ç¾ã§ããã¤ãã³ãä¸ã« 1 ã¤ããåèªãç¾ãããªãã¨ãã« * ã使ã£ã¦ãã¨ã©ã¼ã«ã¯ãªãã¾ããããã®ãããªå ´åã«ã¯ç©ºæååãè¿ããã¾ãã x* x-$ ã®çç¥å½¢ã§ãã x- x* ã¨åæ§ã« x-$ ã®çç¥å½¢ã§ããããã ãæå¾ã®åèªã¯å«ã¿ã¾ããã ã¤ãã³ãæå®ãªãã«åèªæ示åãä¸ããããå ´åãç´åã®ã³ãã³ããã¤ãã³ãã¨ãã¦ä½¿ããã¾ãã
修飾å (Modifiers)
åèªæ示å (çç¥å¯è½) ã®å¾ã«ã¯ã以ä¸ã«ç¤ºã修飾åãã1 å以ä¸ã®ã·ã¼ã±ã³ã¹ã®ããã¡ã§ç½®ãã¾ããããããã®ä¿®é£¾åã®åã«ã¯ `:' ãã¤ãã¾ãã h ãã¹åããæ«å°¾ã«ããé¨å (ãã¡ã¤ã«å) ãåãé¤ããåã®æ¹ (ãã£ã¬ã¯ããªé¨) ã ããæ®ãã¾ãã t ãã¹åããåã®æ¹ (ãã£ã¬ã¯ããªé¨) ãåãé¤ããæ«å°¾ã«ããé¨å (ãã¡ã¤ã«å) ã ããæ®ãã¾ãã r æ«å°¾ã«ãã .xxx å½¢å¼ã®ãµãã£ãã¯ã¹ãåãé¤ãããã¼ã¹å (basename) ã ããæ®ãã¾ãã e æ«å°¾ã®ãµãã£ãã¯ã¹ã ããæ®ãã¦ãå ¨ã¦ã®é¨åãåãé¤ãã¾ãã p æ°ããã³ãã³ãã表示ãã¾ãããå®è¡ã¯ãã¾ããã q ç½®æãè¡ãããåèªãã¯ã©ã¼ããããã以ä¸ã®ç½®æãè¡ãããªãããã«ãã¾ãã x q ã¨åãããã«ç½®æå¾ã®åèªãã¯ã©ã¼ããã¾ããã 空ç½æå ã¨æ¹è¡æåã®ã¨ããã§åèªã«åå²ãã¾ãã s/old/new/ ã¤ãã³ãè¡ã§æåã«ç¾ããã old ã new ã«ç½®ãæãã¾ãã/ ã®ä»£ããã«ä»»æã®åºåãæåã使ããã¨ãã§ãã¾ããæå¾ã®åºåãæåãã¤ãã³ãè¡ã®æå¾ã®æåãªãã°ãããã¯çç¥ã§ãã¾ãã old 㨠new ã®ä¸ã§ã¯ãããã¯ã¹ã©ãã·ã¥ 1 ã¤ã§ã¯ã©ã¼ãããã°åºåãæåã使ãã¾ãã new ã« & ãå«ã¾ãã¦ããå ´åã«ã¯ããã㯠old ã«ç½®ãæãããã¾ããããã¯ã¹ã©ãã·ã¥ 1 ã¤ãåã«ç½®ãã° & ãã¯ã©ã¼ãã§ãã¾ãã old ã空æååãªãã°ãããã«ã¯ååã«ç½®æããã old ãè¨å®ããã¾ãã以åã«å±¥æ´ç½®æãå ¨ãè¡ããã¦ããªãå ´åã«ã¯ãç¾å¨ã«ä¸çªè¿ã !?string[?] ã®æ¤ç´¢ã§ä½¿ããã string ãè¨å®ããã¾ãã & ç´åã®ç½®æãç¹°ãè¿ãã¾ãã g å¤æ´ãã¤ãã³ãè¡å ¨ä½ã«é©ç¨ãã¾ãããã㯠`:s' ã¨çµã¿åããã¦ä½¿ããã¾ã (ä¾:`:gs/old/new/')ã `:s' ã¨ä¸ç·ã«ä½¿ã£ãå ´åã«ã¯ã / ã®ä»£ããã«ä»»æã®åºåãæåã使ãã¾ããã¾ãæå¾ã®åºåãæåãã¤ãã³ãè¡ã®æå¾ã®æåãªãã°ãããã¯çç¥ã§ãã¾ãã
UNIXã·ã§ã«ã¹ã¯ãªããã³ãã³ãããã¯
- ä½è : å±±ä¸å²å ¸
- åºç社/ã¡ã¼ã«ã¼: ã½ãããã³ã¯ã¯ãªã¨ã¤ãã£ã
- çºå£²æ¥: 2005/05/25
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 5人 ã¯ãªãã¯: 33å
- ãã®ååãå«ãããã° (7件) ãè¦ã