Perl escaping argument for bash execution

前端 未结 5 1543
感动是毒
感动是毒 2020-12-21 11:16

I\'ve written some code in Perl which executes some bash command within its execution. My problem was when bash command attributes contained white space inside which failed

5条回答
  •  悲哀的现实
    2020-12-21 11:29

    It's much easier to use single quotes in bash; then the only character you need to worry about is a single quote itself.

    ($arbitrary_string) =~ s/'/'"'"'/g;
    
    `echo '$arbitrary_string'`
    

提交回复
热议问题