は「任意の文字」を意味.
するメタ文字です。sed
その特別な意味を抑制するには、バックスラッシュでエスケープします。
sed -e 's%/\.\./%/%g' $src_file > $temp_file
そのようなものを削除した後、別のファイルを参照していることに注意してください/../
。以前と同じ名前を参照するには (複雑なシンボリック リンクがない場合)、. の前のディレクトリ コンポーネントを削除する必要があります/../
。したがって:
some/../path/to/file
path/to/file
はディレクトリであり、他の場所のシンボリックリンクではないと仮定して、同じファイルを参照しますsome
が、一般的にsome/path/to/file
は別のファイルです (ただし、シンボリックリンクを使用してそのアサーションを混乱させることができます)。
$ x="some/../path/to/file
> some/ab/path/to/file
> /some/path/../to/another/../file"
$ echo "$x"
some/../path/to/file
some/ab/path/to/file
/some/path/../to/another/../file
$ echo "$x" | sed -e 's%/\.\./%/%g'
some/path/to/file
some/ab/path/to/file
/some/path/to/another/file
$ echo "$x" | sed -e "s%/\.\./%/%g"
some/path/to/file
some/ab/path/to/file
/some/path/to/another/file
$ echo "$x" | sed -e s%/\.\./%/%g
some/path/file
some/path/file
/some/path/to/another/file
$ echo "$x" | sed -e s%/\\.\\./%/%g
some/path/to/file
some/ab/path/to/file
/some/path/to/another/file
$
コマンド"$x"
内で変数を二重引用符で囲むことに注意してください。echo
代入で一重引用符または二重引用符のいずれかを使用でき、同じ結果が得られました。
Mac OS X 10.7.4 で標準sed
(シェルは/bin/sh
3.2.x bash
) でテストしますが、結果はどのシステムでも同じです。