Replacements for ampersand and double-ampersand in PowerShell
The &
operator in PowerShell is just the ;
or Semicolon.
The &&
operator in PowerShell has to be run as an if
statement.
Command ; if($?) {Command}
Example:
tsc ; if($?) {node dist/run.js}
Try this function, which can be used roughly the same way:
function aa() {
if($?) {
$command = [string]::join(' ', $args[1..99])
& $args[0] $command
}
}
Now &&
can be replaced with ; aa
, which while still not perfect is a lot more succinct.
cls && build
becomes
cls; aa build