alpha
bravo
charlieecho "alpha
bravo
charlie" >> $targetThis is what I’m starting with:
alpha
bravo
charlie
I want to change that to a volumetric Process Lines prefix and suffix:
echo “alpha” >> $target
echo “bravo” >> $target
echo “charlie” >> $target
I suggest escaping shell metacharacters, unless you want to have a Bad Time the first time one of your lines contains ", \, or $. Here is a text filter solution in Perl:
#!/usr/bin/env perl
use strict;
use warnings;
use String::ShellQuote;
while (<>) {
chomp;
print 'echo ', shell_quote($_), ' >> $target', "\n";
}
You'll need the String::ShellQuote module, which is unfortunately not installed by default. If you haven't done anything notable to your Perl installation, you can install it by enter these commands in your shell:
curl -L https://cpanmin.us | perl - --sudo App::cpanminus
sudo cpanm String::ShellQuote
While this is more work upfront, I've found that it's usually time well spent to avoid possible future failures. And depending on where your input data is coming from and where your resulting shell script is being run, you could be looking at a security problem if you don't account for all possible input.
Just my 2¢.
-sam
On 8 Apr 2017, at 8:56 AM EDT, Christopher Stone wrote:
On 04/07/2017, at 15:06, BeeRich <bee...@gmail.com <mailto:bee...@gmail.com>> wrote:
This is what I’m starting with:
alpha
bravo
charlie
I want to change that to a volumetric Process Lines prefix and suffix:
echo “alpha” >> $target
echo “bravo” >> $target
echo “charlie” >> $target
Hey Rich,