5

With Bash, you have the command :

Null command.

No effect; the command does nothing.

Exit Status:
Always succeeds.

Example

: 'foo'

Does PowerShell have something similar to this?

Zombo
  • 1
  • 62
  • 391
  • 407
  • @DejanDakić `;` would not work with my example. It would generate `foo` instead of nothing. – Zombo Jul 21 '14 at 05:51
  • Use `Out-Null` to delete the output, if that's what you're seeking, as in `'foo' | Out-Null` – PeterK Jul 21 '14 at 05:51
  • @StevenPenny: My assumption was that if 'foo' isn't executed, then it's not required, but then I guess I fundamentally misunderstood the docs I found on the colon operator. – PeterK Jul 21 '14 at 07:04

2 Answers2

3

With the above example, the ForEach-Object alias % works

% 'foo'

Or

function : {}
: 'foo'

Or

[void] 'foo'

PowerShell Data Types

Zombo
  • 1
  • 62
  • 391
  • 407
  • Could you please explain what the code in your second example actually means? Isn't the colon supposed to be for variable namespaces in PowerShell? Why aren't both lines syntax errors? Thanks! – Scott Gartner Mar 19 '21 at 05:01
0

Another even shorter solution is to use the alias of Where-Object which is ?.

This command line does nothing (and succeeds):

? .

The trick is simply to pass a single-character argument so that the command does not fail and which has no special meaning in powershell.

adamency
  • 682
  • 6
  • 13