powershell - variable expansion inside namespace-qualified variable name -
problem
i want perform parametric variable evaluation. to-be-evaluated variable name constructed string concatenation - namespace part , name part being defined in variable. example: env:$var, value of $var is, instance "os". however, while using expression
${env:os} gives expected value windows_nt, construct
$var="os" ${env:$var} is null-valued expression.
motivation
i'm not intereseted in value of environment variables (but simplest example, find). want, refer content of file via ${c:<filename>} construct. want perform several, conditional in-file string substitutions and, i'd use construct similar this:
<identify files in foreach> ${c:<filename>} -replace 'this', 'that' > ${c:<new filename>} to achieve this, need <filename> value of iterator variable.
question
if value of $var os, shall @ ..., if expect value of following expression windows_nt?
${env:...var...}
use get-childitem on env: psdrive , expand value of result:
(ls env:$var).value edit: @petseral suggested in comments using get-content more elegant approach:
(cat env:$var)
Comments
Post a Comment