0

I looking for this in powershell

$VAR0=args[0]
$VAR1=args[1]
$VAR2=args[2]

With a construction like this

$a=0
$VAR+$a=args[$a]

but I cannot concatenate this way

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • `$VAR0,$VAR1,$VAR2 = $args[0], $args[1], $args[2]`, this what you mean? – Abraham Zinala Apr 11 '22 at 13:46
  • nope, in $VAR0 I need 0 as a variable; like $a=0 $VAR+$a= args[$a] – Spacey_Globule Apr 11 '22 at 13:49
  • **_doing what you describe is a well known BIG FAT ERROR._** [*grin*] don't do that - you already have it all in a nice, solid, easy-to-use $Var ... the `$Args` collection ... so use it instead of making your code more complex for no reason at all. – Lee_Dailey Apr 11 '22 at 14:02
  • What you're looking for is _variable indirection_, where you refer to a variable _indirectly_, via its name stored in a different variable or provided by an expression. PowerShell enables this via the [`Get-Variable`](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/get-variable) and [`Set-Variable`](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/set-variable) cmdlets, but note that there are usually better alternatives. See [the linked duplicate](https://stackoverflow.com/q/68213804/45375) for details. – mklement0 Apr 11 '22 at 14:16

0 Answers0