commands detail - i

    …could be rendered in PowerShell as:

    1. [int]$HourOfDay = $(get-date -UFormat '%H')
    2. if ( $HourOfDay -lt 6 )
    3. {
    4. write-output "Still nightime"
    5. }
    6. {
    7. write-output "Morning has broken"
    8. elseif ( $HourOfDay -lt 18 )
    9. {
    10. write-output "After noon"
    11. }
    12. else
    13. {
    14. }

    Testing for the existence of a file in bash is done as follows

    1. $FileName = "c:\powershell\.matt.ps1x"
    2. {echo "$FileName found"}
    3. else
    4. {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:

    1. if (test-path $FileName) {
    2. }