LoginSignup
5

More than 5 years have passed since last update.

[小ネタ]perlワンライナーにシェル変数を渡す

Last updated at Posted at 2015-12-07

-sオプションを使います


echo -e "hogehoge\nfugafuga" > myfile.txt

var="hogehoge\n";cat myfile.txt | perl -pse 's/$shell_var//' -- -shell_var=$var

出力はfugafugaとなります

--以降で変数の中身を指定していますが、これはシェル一般に共通する記法ではなく、特殊な記法だと思われます

訂正:シェル組み込みの文法ではないですが、コマンドラインツールの作成時に推奨されている記法のようです。(以下を参照)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5