简体   繁体   中英

Running a perl command in a bash script on OSX

Ok noob question here.

I have a bash script on a mac which runs a perl command. More specifically I want to run the following on a text variable

...

mytext=...

...

perl -pe 's/-\K(\w)/\U$1/g' ${mytext}

But I just get -

Can't open perl script "mytextis": No such file or directory

Any ideas?

Do like this:

perl -pe 's/-\K(\w)/\U$1/g' <<< ${mytext}

This way the content of ${mytext} is used as standard input for the perl script, otherwise the shell treats it as a command line argument, which then perl treats as a filename to read a script from.

The <<< is a Here String , a variant of Here Documents . You can read about it in man bash , in the section Here Strings .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM