It returns true
if the last command was successful, else false
.
However, there are a number of caveats and non-obvious behaviour (e.g. what exactly is meant by "success"). I strongly recommend reading this article for a fuller treatment.
For example, consider calling Get-ChildItem.
PS> Get-ChildItem
PS> $?
True
$? will return True
as the call to Get-ChildItem succeeded.
However, if you call Get-ChildItem on a directory which does not exist it will return an error.
PS> Get-ChildItem SomeDirectoryWhichDoesNotExist
Get-ChildItem : Cannot find path 'C:SomeDirectoryWhichDoesNotExist' because it does not exist.
PS> $?
False
$? will return False
here, as the previous command was not successful.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…