别名

2012-04-20 68 views
0

我想能够设置内的别名做这样的事情:别名

> function gitb(){ git checkout -b $1; alias $1='git checkout $1'; } 
> gitb sample 
Switched to a new branch 'sample' 
> git checkout master 
Switched to branch 'master' 
> sample 
Switched to branch 'sample' 

但是,功能gitb并不像预期的那样,因为:

> alias sample 
alias sample='git checkout $1' 

,而不是

> alias sample 
alias sample='git checkout sample' 

有谁能告诉我如何实现我想要的吗?

回答

2

了解单引号和双引号之间的区别。

function gitb() { git checkout -b $1; alias $1="git checkout $1"; } 
+0

双引号?就像'''...''' 但是,它们并没有像你们那样彼此接近。 – 2012-04-20 03:38:21

+0

“”是一个独特的字符;在美式键盘上,它是由shift +''生成的字符,ASCII值是0x22。 – geekosaur 2012-04-20 03:42:47