Saturday, November 11, 2017

How To "Variablize" Your Environment Settings

You have

export bad_guy='machiavelli_the_3.12.3'
export path = 'x:y:z:/usr/lib/machiavelli_the_3.12.3'
export bad_home='/usr/lib/share/utils/machiavelli_the_3.12.3/bin'

you get the idea. You want to upgrade machiavelli to an even more devious character - once - in ONE place.

So you'd rather see :

export bad_guy='machiavelli_the_3.12.3'
export path = 'x:y:z:/usr/lib/'$bad_guy''
export bad_home='/usr/lib/share/utils/'$bad_guy'/bin'

You get the idea..

This is the best I have .. not even sure how to google this.. Pretty inelegant. Also,  you can't just pipe your existing file through this in your editor :(

#!/usr/bin/perl

$file = shift;
$var = shift;

$sys = "grep $var $file";

$var_line = `$sys`;

$val = (split( /'/ , $var_line ))[1];

print $var_line ;

$sys = q{grep -v }.$var.' '.$file.q{ | perl -p -e 's/\b}.$var_val.q{\b/\047\$}.$var.q{\047/;'};

$rem = `$sys`;

print $rem;

No comments: