powershell - In PowerShell, is it possible to create an alias whose name has a space in it?
问题描述
I want to make rm -rf
an alias for Remove-Item
, since I keep accidentally typing it when using PowerShell.
I had guessed maybe I could do something like this, but that doesn't work.
Set-Alias -name 'rm -rf' -value Remove-Item
解决方案
You could also remove the default alias and then replace it with a custom function.
# remove default alias
if (Test-Path Alias:rm) {
Remove-Item Alias:rm
}
# custom function for 'rm'
function rm {
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[switch]$rf,
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Path
)
process {
Remove-Item -Path $Path -Recurse:$rf -Force:$rf
}
}
Then call it like this:
rm -rf "C:\Temp\dir"
If course, so far this function doesn't have the full functionality of Remove-Item
, but you can extend it as you like.
Note: Even though this "solves" your problem in the short-run, you should not revert to these kinds of workarounds. Better get accustomed to the actual PowerShell commands and syntax, or you're bound to run into more problems sooner or later.
推荐阅读
- amazon-web-services - 根据文件名删除 S3 对象
- java - 使用图像作为 seekBar,带有百分比
- java - 线程“主”java.lang.AbstractMethodError SpringBoot 中的异常
- python - AWS SageMaker 训练脚本:如何传递自定义用户参数
- c - 双递归函数后使用顺序索引扫描数组
- gem5 - 如何在 se 模式下使用 gem5 中的 m5ops,例如 m5_exit 和 m5_dump_stats
- workflow - YOUTrack 工作流程因一个项目而失败
- java - 无法通过 Spring Boot 调用 https REST 端点
- json - 无法在 PySpark 中查询 JSON 制作的数据框列
- .htaccess - 需要正确的 htaccess 重定向语法