# Detect NAME=Value in shell script. # my $findShellVar = qr/\b([-A-Z0-9_]+)=\"(.*?)\"{1}?/sgc; # Detect embedded use of vars: NAME="text $VAR" # my $embeddedVar = qr/$\{?([-_[:alnum:]]+)\}?/gs; # For each line of the shell script, find shell variable # assignments, substituting the assigned value for any use # of other variables, and store result in hash. # while my $line ( ) { if ( $line =~ /$findShellVar/ ) { my ( $k, $v ) = ( $1, $2 ); $v =~ s/$embeddedVar/$vars{$1}/; $vars{$k} = $v; } }