[CentOS] Assitance with perl

Thu Feb 3 04:34:20 UTC 2022
Jon LaBadie <jcu at labadie.us>

On Wed, Feb 02, 2022 at 08:54:38PM -0500, H wrote:
>>>> I am writing a long bash script under CentOS 7 where perl is used for manipulating some external files. So far I am using perl one-liners to do so but ran into a problem when I need to append text to an external file.
>>>> Here is a simplified example in the bash script where txt is a bash variable which I built containing a longish text with multiple newlines:
>>>> txt="a b$'\n'cd ef$'\n'g h$'\n'ij kl"
>>>> A simplified perl one-liner to append the text in the variable above to some file in the bash script would be:
>>>> perl -pe 'eof && do{print $_'"${txt}"'; exit}' someexternalfile.txt
>>>> This works when fine when $txt does /not/ contain any spaces but falls apart when it does.

In a shell script why not stick to shell tools?

   printf "%s" "${txt}" >> someexternalfile.txt

Jon H. LaBadie                  jcu at labadie.us