0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[PowerShell] スクリプトブロックを使えば環境を汚さないワンライナーが書ける

0
Posted at

{} ←スクリプトブロック
&{} ←スクリプトブロックを作って即実行

基本的に外の変数に作用しない
$n = 10

&{$n++; echo $n}
# 11
&{$n++; echo $n}
# 11

$n
# 10
ただし、globalスコープ等を使うと外に作用してしまう
$n = 10

&{$global:n=5; echo $n}
# 5

$n
# 5
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?