passing bash variable to perl command in bash script

Recently I tried passing a bash variable to perl command in bash script, it didn’t end well.

Troy Engel from http://tacticalvim.wordpress.com/ was nice enough to point out the issue:

use sed instead of perl for what you need; it’s simpler, faster and uses the bash variables easily.

I set up a test script /home/someuser/test.sh to show:

What’s important to note is that A, you *must* use double-quotes in the sed expression so that variable expansion works; single-quotes inhibits expansion. B, as you found out, you need to use something other than “/” as your expression separator since you have a replacement variable with that character in it. I used pipes in sed, but you could use almost anything (“#”, etc.) for the same effect.

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>