commands detail - i
…could be rendered in PowerShell as:
[int]$HourOfDay = $(get-date -UFormat '%H')
if ( $HourOfDay -lt 6 )
{
write-output "Still nightime"
}
{
write-output "Morning has broken"
elseif ( $HourOfDay -lt 18 )
{
write-output "After noon"
}
else
{
}
Testing for the existence of a file in bash is done as follows
$FileName = "c:\powershell\.matt.ps1x"
{echo "$FileName found"}
else
{echo "$FileName not found"}
[1] The way I’ve rendered the PowerShell here isn’t great, but I’ve left it like that because for a couple of reasons. First, it shows the similarity between PowerShell and Bash, which I think is encouraging for anyone reading this e-book. Second it allows me make a brief point about using aliases.
echo
is handy. It’s short, and it looks like it does the same thing as echo
in Unix, MS-DOS and probably a few other languages besides. It pretty much does…but does echo
alias write-output
which allows you to pipe to other PowerShell commands, or does it alias to write-host
, which doesn’t?
Also, in PowerShell scripts rather than this:
…it would typically be seen as better to format using one of these two alternatives:
if (test-path $FileName) {
}