Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.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
Windows 将git descripe设置为shell变量_Windows_Git_Shell_Command Line - Fatal编程技术网

Windows 将git descripe设置为shell变量

Windows 将git descripe设置为shell变量,windows,git,shell,command-line,Windows,Git,Shell,Command Line,我想根据git descripe命令的输出创建一个目录 这不起作用: set NAME = git describe mkdir %NAME% 我该怎么办?在Windows上,您可以尝试上述方法 现在,如果您使用的是Linux,以下操作可能会起作用: 试试这个: # Create the command alias your-command="mkdir $(git describe)" # Run the command your-command 应创建一个名为的文件夹,其输出为git

我想根据
git descripe
命令的输出创建一个目录

这不起作用:

set NAME = git describe
mkdir %NAME%

我该怎么办?

在Windows上,您可以尝试上述方法

现在,如果您使用的是Linux,以下操作可能会起作用:

试试这个:

# Create the command
alias your-command="mkdir $(git describe)"

# Run the command
your-command
应创建一个名为的文件夹,其输出为
git descripe

这是在ubuntu安装上测试的,它只能在存储库文件夹中工作

请注意,所述命令会创建别名。如果要将
git descripe
的输出设置为shell变量,应执行以下操作:

# Create a local variable
foo=$(git describe)

# Create a new folder using `mkdir`
mkdir ${foo}
请注意,现在您有了一个值为
git descripe
的局部变量。您可以尝试:

echo ${foo}

在Windows中,要捕获命令的输出,可以使用
FOR/F
命令

请阅读
的帮助,然后尝试此操作

 FOR /F %a in ('git describe') do md %a

你说得对,我没注意到标签。编辑澄清!这看起来解决了问题。我很好奇,如果使用Eval,它会工作吗?比如
set NAME=Eval(git descripe)
。不幸的是,我的windows机器没有启动,所以我现在无法测试它。不管怎样,只是好奇而已。谢谢参考:Eval是一个VB函数,它不是Windows命令,因此不能在Windows命令行中执行。