How to assign the effect of command execution to a variable like a shell under bat batch processing

How to achieve the same as shell under bat, assign the result of executing the command line to a variable?

At the beginning, it was really difficult for me. With the deepening of familiarity with bat batch processing knowledge.

Learned! ! !

 

Take a chestnut:

svnlook uuid C:\Repository\test # What does this command mean? It is the command of the svn server (because I have been doing svn stuff recently).

                                                              # So the effect of this command is to return the UUID of the test warehouse

 

The shell will be implemented like this:

UUID=`svnlook uuid C:\Repository\test` # here is · oh. This symbol is the one under the ESC button on the keyboard (so small...)

 

==================================================

Ok~~~ See, it's really easy to implement under the shell, and it can also be implemented under bat, but it's a little troublesome.

 

dos下:          for   /f   “delims=”  %t   in  ('svnlook uuid C:\Repository\test')  do  set  UUID=%t   

bat文件中:    for   /f   “delims=”  %%t   in  ('svnlook uuid C:\Repository\test')  do  set  UUID=%%t

 

The difference above is that the execution under dos is %t, and the execution in the bat file is %%t.

Also, it should be noted that single quotation marks are used in (), because single quotation marks in bat refer to the meaning of the command.

The delims value here is the meaning of the separator. I wrote "delims=" here. There is no separator, so line splitting is performed,

This will get the result of the first row.

 

Learned this, and then write bat. The script written is more beautiful and more concise. You can go up to 10 floors in one go. Ha ha.

   

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324963408&siteId=291194637