スクリプトがあります~/bin/script
$ cat ~/bin/script
#!/bin/bash
perl -pe 's/loremipsum/`cat ~/foo/bar/file.txt`/ge' -i ~/path/to/target.txt
スクリプトは、loremipsum
inの各インスタンスをのコンテンツに置き換える必要があります。ただし、返品発行target.txt
file.txt
script
Backticks found where operator expected at -e line 1, at end of line
(Missing semicolon on previous line?)
Can't find string terminator "`" anywhere before EOF at -e line 1.
私のスクリプトに問題がありますか?
ベストアンサー1
バックティック結果をスクリプト変数に保存し、Perl呼び出しに使用する必要があります。
REPL = `cat ~/foo/bar/file.txt`
perl -pe "s/loremipsum/$REPL/ge" -i ~/path/to/target.txt
しかし、foo/bar/file.txtの内容がコマンドを破損する可能性があるので、Perlスクリプトを使用して文字列をファイルの内容に置き換える方が良いと思います。