How can I make a shell script using Perl?

I have a Perl script called replaceUp:

 #!/usr/bin/perl                                          

 search=$1
 replace=$2

 find . -type f -exec perl -p -i -e "s/$search/$replace/g" {} \;

      

script is not loading. This suggests that my script is wrong.

How do I make a shell script using Perl?

+1


a source to share


1 answer


The first line should be #!/bin/sh

, not #!/usr/local/bin/perl

. You are mistaken that this is a Perl script; it is a shell script that calls Perl.

It won't work either, because $ search and $ replace won't be interpolated inside single quotes. Try single quotes inside double quotes.



Or better yet, try my bulk search / replace Perl script . I keep a pure-Perl script for this because, as dangerous as bulk search / replace, you don't need multiple levels of interpretation of the shell meta-character, taking it from dangerous to completely deadly.

+10


a source







All Articles