Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/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
使用git命令和双引号将批处理脚本写入文件_Git_Batch File - Fatal编程技术网

使用git命令和双引号将批处理脚本写入文件

使用git命令和双引号将批处理脚本写入文件,git,batch-file,Git,Batch File,我在git调用中获得了以下批处理脚本: @echo off ECHO ^" > test.txt ECHO &call git describe >> test.txt ECHO ^" >> test.txt 我真正想要的是拥有 "theGitDescribeContent" 在test.txt文件中 但我从批量srcipt中真正得到的是 " theGitDescribeContent " 我查阅了一些网站,了解如何在没有换行符的情况下写入文件,但没有

我在git调用中获得了以下批处理脚本:

@echo off
ECHO ^" > test.txt
ECHO &call git describe >> test.txt
ECHO ^" >> test.txt
我真正想要的是拥有

"theGitDescribeContent"
在test.txt文件中

但我从批量srcipt中真正得到的是

"
theGitDescribeContent
"
我查阅了一些网站,了解如何在没有换行符的情况下写入文件,但没有成功。e、 g

echo|set /p="^"" > test.log
echo|set /p=&call git describe >> test.log
echo|set /p="^"" >> test.log
看起来它不像

echo|set /p="^"" > test.log
因为它不在test.log和

echo|set /p=&call git describe >> test.log
产生

theGitDescribeContent


//a new line after the content above
这应该很简单,但我已经花了一个小时的时间在网上寻找解决方案

感谢您的帮助。

对于批量sript:

@echo off
set "tag="
for /f %%i in ('git describe') do set "tag=%%i"
echo "%tag%"> test.txt
如果在命令行中运行,请使用
%i
插入的
%i


正如@aschipfl所评论的,答案需要更新,从
echo^“%tag%^”>test.txt
echo”%tag%>test.txt
,在
var=value
周围添加双引号,非常感谢!那太好了!除此之外,我想知道您在这里使用了什么技术,您有什么建议我可以在哪里阅读更多关于这方面的内容吗?@J.Chen我刚才在谷歌上搜索了
如何将输出分配给批处理中的变量
。您将看到不同的方法。至于详细信息,您可能需要阅读一些有关批处理脚本编写的教程。为什么要在此处转义引号(
^“
)?这不是必需的。您应该删除
前面的空格,或者编写
>test.txt echo”%tag%“
为避免输出尾随空格…不客气!最后,我建议使用引用的
set
语法,如
set“VAR=Value”
以避免特殊字符的麻烦,并避免意外的(不可见的)尾随空格…
echo | set/p=“^”“>test.log
不起作用,因为
^
出现在
之间“
,因此不会对其进行求值,然后会出现不平衡的引号;使用
set/P=^”“test.log
代替。。。