- Settings:
Page
Normal
Plain layout without fancy styles
Font
Normal
Large fonts
Very large fonts
Colour
Normal
Restful colour scheme
Light text on a dark background

Note: user account creation on this site has been disabled.

Programming, speculative fiction, science, technology
Powered by Drupal, an open source content management system
Scope
Include Children
If you select a term with children (sub-terms), do you want those child terms automatically included in the search? This requires that "Items containing" be "any."
Categories

Everything in the Events vocabulary

"Events" is used for: Convention Post, Page, Story.

People mentioned in the articles

"People" is used for: Page, Convention Post, Story.

Themes mentioned in the article

"Themes" is used for: Page, Convention Post, Story.
Skip to top of page

Adventures in Powershell: you thought you could ignore that empty line

Powershell is powerful. But if you forget that it's a scripting language, and approach it as a programming language, you (like me) may be thrown off, time and time again, by its certain... literalness.

I have a script that reads Powershell variable / value pairs from a file we shall call foo.conf . In other words, foo.conf looks like this:

$var1 = "bla1"
$var2 = "bla2"
$var3 = "bla3"

etc.

After reading the contents of this file, it needs to execute those variable assignments. It does it all in this line:

Get-Content("foo.conf") | ForEach-Object { Invoke-Expression($_) }

If foo.conf has empty lines, those values of $_ will be empty. And when it tries to execute Invoke-Expression($_), it will give an error about not being able to invoke a command with an empty argument, or something like that. It's takes time to figure out that the empty argument is due to the empty line in foo.conf, because, depending on what text editor you use, you may not even notice an empty line at the end of the file. (I use emacs, and it does not show me empty lines. Perhaps there is some mode that would show it, but it didn't even occur to me that I would ever need such a thing.)

You are probably asking, why can't I just dot-source foo.conf? Well, for that it would have to have a .ps1 extension -- you can't dot-source a file Powershell doesn't recognize as a script. But since this file of name-value pairs is essentially a configuration file, that's a reason to give it a .conf extension -- maybe all the configuration files in your project have such extensions, and you don't want to deviate from the convention.