PowerShellでブール値を表すにはどうすればよいでしょうか?

変数 $a に trueを直接代入しようとすると次のようになります。

PS > $a = true
用語 'true' は、コマンドレット、関数、操作可能なプログラム、またはスクリプト ファイルとし
て認識されません。用語を確認し、再試行してください。
発生場所 行:1 文字:9
+ $a = true <<<<

true はブール値として認識しません。

実は、PowerShellではブール値を先頭に$を付けて $TRUEや$FALSE と表します。

PS > $a = $TRUE
PS > $a.GetType()
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Boolean                                  System.ValueType

Null値も同様に、先頭に$を付けて $NULL と表します

PS > $a = $NULL
PS > $a.GetType()
null 値の式ではメソッドを呼び出せません。
発生場所 行:1 文字:11
+ $a.GetType( <<<< )

エラーが発生していますがこれは正常な処理です。

変数の値がNullなのでGetType()メソッドを実行できずにエラーとなっているからです。


Posted in: PowerShell , PowerShell入門  Tags:

最新のブログ

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

コメントを書く


 

  Country flag

biuquote
  • コメント
  • プレビュー
Loading



Calendar

«  11月 2008  »
月曜火曜水曜木曜金曜土曜日曜
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
View posts in large calendar

Recent Posts

Recent Comments

Banners

Theme Grabber
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008 PowerShell from Japan!!