Normally, bash replaces an undefined variable with an empty string:
$ echo "$BLAH things after blah"
things after blah
But there's a handy way to change this behavior:
$ set -u
$ echo "$BLAH things after blah"
sh.exe": BLAH: unbound variable
(Pardon the exe
. I'm running under MSYS bash.) I put this at the top of all my bash scripts. (Fail fast being a Good Thing and all that.)
PowerShell normally behaves the same way as bash:
PS C:\> echo "$blah things after blah"
things after blah
My question: Is there any thing in PowerShell that changes this behavior so it will cause an error when I attempt to use an uninitialized variable?
This should do the trick:
set-strictmode -version 2.0
http://technet.microsoft.com/en-us/library/hh849692.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With