使用别名作为参数

huangapple go评论69阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年7月24日 20:15:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76754414.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定