BATsh

 view release on metacpan or  search on metacpan

lib/BATsh/Env.pm  view on Meta::CPAN

        return;
    }
    %STORE = %{pop @SETLOCAL_STACK};
}

# Expand %VAR% references in a CMD string
# %% is literal % in a batch file context
sub expand_cmd {
    my ($class, $str) = @_;
    return '' unless defined $str;
    # Replace %%VAR%% (double-percent FOR variables) with their values
    $str =~ s/%%([A-Za-z])/defined($STORE{"%%$1"}) ? $STORE{"%%$1"} : "%%$1"/ge;
    # Replace %VAR%
    $str =~ s/%([^%\r\n]+)%/defined($STORE{$1}) ? $STORE{$1} : ''/ge;
    # %% -> % (literal percent in batch files)
    $str =~ s/%%/%/g;
    return $str;
}

# Expand $VAR and ${VAR} references in a SH string
# Also handles $? (last exit code), handled by caller
sub expand_sh {
    my ($class, $str) = @_;
    return '' unless defined $str;
    # ${VAR}



( run in 1.748 second using v1.01-cache-2.11-cpan-39bf76dae61 )