Bool値とNull値の表し方(PowerShell 入門)

by HIRO 19. 8月 2008 23:38

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()メソッドを実行できずにエラーとなっているからです。

最新のブログ

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

Tags:

PowerShell | PowerShell入門

コメントを書く


 

  Country flag

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



Calendar

<<  3月 2010  >>
月曜火曜水曜木曜金曜土曜日曜
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 PowerShell from Japan!!