英文:
Use alias as parameter
问题
在Linux终端中,我想能够将别名用作参数,而不仅仅是单个命令,对所有命令都使用相同的参数。
例如,不是执行 git push origin HEAD
,我可以这样做:
alias H='HEAD'
git push origin H
这只是一个示例,我是否也可以在Git之外的命令或参数中创建占位符?
英文:
on linux terminal i would like to be able to use an alias as a parameter, and not for a single command, the same parameter for all commands.
for example instead of doing git push origin HEAD
I can do:
alias H='HEAD'
git push origin H
Is it just for example, can I create placeholders for commands or parameters outside of Git as well?
答案1
得分: 1
bash
别名不是这样工作的。只有当它们出现在命令位置或在以空格结束的别名扩展之后才会被展开。
然而,在这个示例中,你真正想要的是让 Git 认识 H
作为 HEAD
的别名,你可以通过创建一个名为 H
的新符号引用,该引用指向 HEAD
来实现。
git symbolic-ref H HEAD
英文:
bash
aliases don't work this way. They are only expanded when they occur in command position, or following an alias expansion that ends in a space.
However, what you really want (in this example, anyway) is for Git to recognize H
as an alias for HEAD
, which you can accomplish by creating a new symbolic reference named H
that refers to HEAD
.
git symbolic-ref H HEAD
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论