简体   繁体   中英

How to run multiple commands in a PowerShell Alias

I'm trying to add an alias to PowerShell in my $profile file.

Set-Alias regrunt grunt;g aa;g cm 'regrunted';g ps;

When I run regrunt , only the first command is run. How can I make this alias run all of the commands?

PS: Please no comments about "do not commit minified files", we have all passed through this.

You can't unfortunately. Aliases in PowerShell can only be for a single command.

You will need to define a function to run multiple commands:

function regrunt {
    grunt;g aa;g cm 'regrunted';g ps;
}

Aliases in PowerShell are designed for a simple renaming of commands. Only one command, no parameters. To do what you want, write a function.

function regrunt {
  grunt
  g aa
  g cm 'regrunted'
  g ps
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM