What is the correct way to pass the Set-Alias ​​parameter to powershell?

A bit of background:

I use PowerShell on Windows XP at work, and I installed a bunch of useful shortcuts in Microsoft.PowerShell_profile.ps1in My Documents, trying to emulate a Mac environment inspired by Ryan Bates shortcuts

I have things like:

Set-Alias rsc Rails-Console
function Rails-Console {Invoke-Expression "ruby script/console"}

Which works fine when on the command line I say:

rsc #it calls the proper command

However, this does not work properly.

Set-Alias rsg Rails-Generate
function Rails-Generate {Invoke-Expression "ruby script/generate"}

So when I do this:

rsg model User

which should cause

ruby script/generate model User

everything that he causes

ruby script/generate  #Dumping  my params

So, how to change my functions correctly to accept the parameters that I send to the functions?

Thank!

+3
source share
1 answer

, , .

:

function Rails-Generate { ruby script/generate $args }

, Invoke-Expression . PowerShell - - .

:

PS Home:\> Set-Alias foo Call-Foo
PS Home:\> function Call-Foo { args }
PS Home:\> foo bar baz
argv[0] = Somewhere\args.exe

PS Home:\> function Call-Foo { args $args }
PS Home:\> foo bar baz
argv[0] = Somewhere\args.exe
argv[1] = bar
argv[2] = baz
+8

Source: https://habr.com/ru/post/1741980/


All Articles