Perl print single quotes from command line script

bash, perl

Solution

You can use ASCII code 39 for `'` to avoid escape hell,

echo text | perl -lnE 'BEGIN{ $q=chr(39) } say "word: $q$_$q\t$q$_$q"'

Problem

The following ``` echo text | perl -lnE 'say "word: $_\t$_"' ``` prints ``` word: text text ``` I need ``` word: 'text' 'text' ``` Tried: ``` echo text | perl -lnE 'say "word: \'$_\' \'$_\'";' #didn't works echo text | perl -lnE 'say "word: '$_' '$_'";' #neither ``` How to correctly escape the single quotes for bash? Edit: want prepare a shell script with a couple of `mv` lines (for checking, before really renames the files), e.g tried to solve the following: ``` find . type f -print | \ perl \ -MText::Unaccent::PurePerl=unac_string \ -MUnicode::Normalize=NFC -CASD \ -lanE 'BEGIN{$q=chr(39)}$o=$_;$_=unac_string(NFC($_));s/[{}()\[\]\s\|]+/_/g;say "mv $q$o$q $_"' >do_rename ``` e.g. from the filenames like: ``` Somé filénamé ČŽ (1980) |Full |Movie| Streaming [360p] some.mp4 ``` want get the following output in the file `do_rename` ``` mv 'Somé filénamé ČŽ (1980) |Full |Movie| Streaming [360p] some.mp4' Some_filename_CZ_1980_Full_Movie_Streaming_360p_some.mp4 ``` and after the manual inspection want run: ``` bash do_rename ``` for running the actual rename...

Original source

Related problems