4 ms·
Disclosure, I work at MSFT and I have a special place in my heart for PowerShell. PowerShell provides incredibly flexible syntax, enough that it can satisfy mo
by guhidalg 7y ago
Disclosure, I work at MSFT and I have a special place in my heart for PowerShell.
PowerShell provides incredibly flexible syntax, enough that it can satisfy most styles of script writing.
The practice you describe (short names in CLI and long names in scripts) can be achieved. A couple of things to note about how PS binds arguments to function calls:
1. If you omit names, the parameters are bound positionally.
1. If you use names, you do not have to type the full name. It is sufficient to type an unambiguous prefix of the parameter name and the most appropriate parameter will be selected.
So for example in the CLI you can just to `ls -r -fi .csproj` whereas in a script you can use the fully self-documenting `ls -Recurse -Filter .csproj`.
Hope this helps!
- partdavid 7y agoAnother commenter complained about short aliases not being safe cross-platform, and this is an example. In powershell core on Unix systems 'ls' is the 'ls' command, not an alias for Get-ChildItem. So I would say the correct "long" version for your example is 'Get-ChildItem -Recurse -Filter .csproj'. In my opinion this is a non-issue (at least when comparing powershell to other shells) because the number of cases where you have to worry about bash command 'X' actually being different from your system (even across varieties of Unix-y OSes) is much greater than this handful of convenience aliases in powershell.
- GordonS 7y agoAs I mentioned though, it's not "safe" to use the shortened aliases cross-platform - I've been bitten by that multiple times before, from memory including `ls` and `wget`.