bashのバッククォートと$()でハマった
以下の問題でハマッた。
$ echo 'aaa "foo.bc" -> "bar.dc"' | sed -re 's/"(([^"]|\\")+)"$/<a>\1<\/a>/' aaa "foo.bc" -> <a>bar.dc</a> $ echo `echo 'aaa "foo.bc" -> "bar.dc"' | sed -re 's/"(([^"]|\\")+)"$/<a>\1<\/a>/'` aaa <a>foo.bc" -> "bar.dc</a>
違いがわからない。
わかった。バッククォート中の文字列の\を解釈してたのか…わかるかorz
$ echo `echo 'aaa "foo.bc" -> "bar.dc"'|tee a.txt | sed -re 's/"(([^"]|\\\\")+)"$/<a>\1<\/a>/'|tee b.txt` aaa "foo.bc" -> <a>bar.dc</a>
もしくは
$ a=aaa;echo `echo 'aaa "foo.bc" -> "bar.dc"'| sed -re "s/\"(([^\"]|\\\\\\\\\")+)\"$/<a href=\"$a\">\1<\/a>/"` aaa "foo.bc" -> <a href="aaa">bar.dc</a>
解釈しないバッククオートってあるの?って$()だよな…つかわねえよ。って俺が甘いのか…
$ echo $(echo 'aaa "foo.bc" -> "bar.dc"'|tee a.txt | sed -re 's/"(([^"]|\\")+)"$/<a>\1<\/a>/'|tee b.txt) aaa "foo.bc" -> <a>bar.dc</a>
一応
$ echo $(echo '\') \ $ echo $(echo "\") > $ echo $(echo "\\") \ $ echo `echo "\\"` bash: command substitution: line 1: unexpected EOF while looking for matching `"' bash: command substitution: line 2: syntax error: unexpected end of file $ echo `echo "\\\\"` \