A small exploration of the bat command: placeholders, judgment statements, and the cmd command of start

The first is the cmd command:

#Start Baidu website with default browser #
start www.baidu.com #Start
Google Chrome to visit Baidu #
start chrome www.baidu.com #Start
Firefox to visit Baidu #
start Firefox www.baidu.com

Now, I want to create a new bat file to execute this command.
First create a basic TXT file and copy the following text into it:

if "%1"=="" (
	start Firefox https://www.huya.com
) else (
	if "%2"=="" (
		start Firefox https://www.huya.com/%1
	) else (
		start Firefox https://www.huya.com/%1/%2
	)
)

Save, modify the file suffix to .bat, and then execute the command in the cmd command window (first switch to the directory where the cmd command is located (shortcut: shift + right key, open the command window here)):

Open cmd window
Then run the cmd command:

search.bat g lol
A window will open:

Run the command:

search.bat xiaozhan

At this time, a window will open:

Now to explain the format of the bat file:
% 1 and% 2 are placeholders for storing variables,
if "% 1" == "" (
) else (
)
is a conditional statement, note Space problem, you must add spaces before and after else, otherwise it will not be recognized

Published 39 original articles · won praise 1 · views 4620

Guess you like

Origin blog.csdn.net/thetimelyrain/article/details/89408608