Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何在git命令(例如git克隆)上放置包装器_Linux_Git_Bash_Shell_Wrapper - Fatal编程技术网

Linux 如何在git命令(例如git克隆)上放置包装器

Linux 如何在git命令(例如git克隆)上放置包装器,linux,git,bash,shell,wrapper,Linux,Git,Bash,Shell,Wrapper,我正试图在git clone命令上添加一个包装器。换句话说,当我键入命令“git clone”时user@server:group/repo.git“git clone命令将触发一个脚本,在脚本中它将。。。 1.克隆git存储库 2.在存储库上运行命令“gitinit” 我之所以要这样做,是因为我希望克隆投影仪以某种方式自动设置。别名所需的命令: alias git='mygit' 创建脚本mygit: #/bin/bash if [ "$1" == "clone" ] ; then

我正试图在git clone命令上添加一个包装器。换句话说,当我键入命令“git clone”时user@server:group/repo.git“git clone命令将触发一个脚本,在脚本中它将。。。 1.克隆git存储库 2.在存储库上运行命令“gitinit”


我之所以要这样做,是因为我希望克隆投影仪以某种方式自动设置。

别名所需的命令:

alias git='mygit' 
创建脚本
mygit

#/bin/bash

if [ "$1" == "clone" ] ; then
  # do your stuff here
  echo special behavior of git clone
else
  command git "$@"
fi
将其保存在PATH变量设置为的某个位置,例如。g<代码>/home/user/bin
chmod 0770


当您在shell中键入
git clone
时,您将启动您的特殊功能。如果你输入e。g
git push
脚本将调用原始git程序。

使用
命令git
绕过别名,而不是
哪个git
。这是内置于shell中的(至少sh和bash都是,我对dash、zsh和其他shell不太确定)。然后,使用
“$@”
避免更改任何用户提供的报价(使用
$*
会导致重新解释由
$IFS
定义的空格)。@torek感谢您的提示。