Weird string expansion with powershell -
i'm using string expansion feature build filenames, , don't quite understand what's going on.
consider:
$basename = "base" [int]$count = 1 $ext = ".ext" $filename = "$basename$count$ext" #filename evaluates "base1.ext" -- expected #now weird part -- watch underscore: $filename = "$basename_$count$ext" #filename evaluates "1.ext" -- basename got dropped, gives? just adding underscore seems throw off powershell's groove! it's weird syntax rule, understand rule. can me out?
actually seeing here trouble in figuring out when 1 variable stops , next 1 starts. it's trying $basename_.
the fix enclose variables in curly braces:
$basename = "base" [int]$count = 1 $ext = ".ext" $filename = "$basename$count$ext" #filename evaluates "base1.ext" -- expected #now wierd part -- watch underscore: $filename = "$basename_$count$ext" #filename evaluates "1.ext" -- basename got dropped, gives? $filename = "${basename}_${count}${ext}" # works $filename hope helps
Comments
Post a Comment