×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

Batch Script MCQs (Multiple-Choice Questions)

Practice Batch Script MCQs with answers and explanations to test your knowledge of Windows Command Prompt, batch files, variables, commands, conditional statements, loops, parameters, file handling, and automation.

Batch Script MCQs

These Batch Script multiple-choice questions cover fundamental and practical concepts used when creating and executing .bat and .cmd files in the Windows Command Shell.

List of Batch Script MCQs

The following Batch Script MCQs include questions on commands, variables, operators, loops, conditions, batch parameters, subroutines, environment localization, redirection, and practical script behavior.

1. Which file extensions are commonly used for Windows batch files?

  1. .bat and .cmd
  2. .sh and .bash
  3. .ps1 and .py
  4. .exe and .dll

Answer: A) .bat and .cmd

Explanation:

Windows batch scripts are commonly stored with the .bat or .cmd extension and are executed by the Command Shell.

2. Which command starts a new instance of the Windows command interpreter?

  1. shell
  2. cmd
  3. command
  4. console

Answer: B) cmd

Explanation:

The cmd command starts a new instance of cmd.exe, the Windows Command Shell.

3. Which command is used to assign a value to an environment variable?

  1. var
  2. set
  3. let
  4. define

Answer: B) set

Explanation:

The set command creates or changes an environment variable. For example, set name=John assigns the value John to name.

4. How is the value of a normal batch variable referenced?

  1. $(name)
  2. {name}
  3. %name%
  4. !name!

Answer: C) %name%

Explanation:

Standard environment-variable expansion in a batch file uses percent signs, such as %name%. Exclamation-mark expansion is associated with delayed expansion.

5. Which command suppresses the display of commands while a batch file executes?

  1. echo off
  2. hide on
  3. silent
  4. quiet

Answer: A) echo off

Explanation:

echo off turns off command echoing. The commonly used form @echo off also prevents the echo off command itself from being displayed.

6. Which command displays a message in a batch script?

  1. print
  2. display
  3. echo
  4. write

Answer: C) echo

Explanation:

The echo command displays text or controls command echoing in the Command Shell.

7. Which command lists files and directories in the current directory?

  1. ls
  2. dir
  3. list
  4. show

Answer: B) dir

Explanation:

The Windows dir command displays a list of files and subdirectories.

8. Which command changes the current directory?

  1. move
  2. cd
  3. goto
  4. path

Answer: B) cd

Explanation:

The cd command, also known as chdir, changes the current directory used by the command interpreter.

9. Which command creates a directory?

  1. md
  2. new
  3. createdir
  4. folder

Answer: A) md

Explanation:

md is an alias for mkdir and creates a new directory.

10. Which command deletes a file?

  1. remove
  2. del
  3. rd
  4. erasefile

Answer: B) del

Explanation:

The del command deletes one or more files. rd or rmdir is used for directories.

11. Which command copies files from one location to another?

  1. copy
  2. cp
  3. clone
  4. duplicate

Answer: A) copy

Explanation:

The Windows copy command copies one or more files to another location.

12. Which command moves a file or directory?

  1. mv
  2. move
  3. transfer
  4. shiftfile

Answer: B) move

Explanation:

The move command moves files or directories from one location to another.

13. Which command displays the contents of a text file?

  1. cat
  2. type
  3. read
  4. showfile

Answer: B) type

Explanation:

The Windows type command displays the contents of a text file in the Command Shell.

14. Which operator redirects command output to a file and overwrites the existing contents?

  1. >
  2. >>
  3. <
  4. ||

Answer: A) >

Explanation:

The > redirection operator sends standard output to a file, replacing existing contents. The >> operator appends output.

15. Which operator appends command output to an existing file?

  1. >
  2. >>
  3. <<
  4. ::

Answer: B) >>

Explanation:

The >> operator redirects output by appending it to the destination file rather than replacing its existing contents.

16. Which symbol is commonly used to write a comment in a batch file?

  1. #
  2. //
  3. REM
  4. --

Answer: C) REM

Explanation:

REM is the standard batch command used to add comments. A line beginning with :: is also commonly used as a comment-like construct, but REM is the documented command.

17. Which syntax correctly checks whether a file exists?

  1. if file test.txt
  2. if exist test.txt
  3. exists test.txt
  4. check test.txt

Answer: B) if exist test.txt

Explanation:

The if exist condition tests whether the specified file or directory exists.

18. Which comparison operator means "equal to" for numeric comparisons in the Batch if command?

  1. EQ
  2. EQU
  3. ==
  4. EQUAL

Answer: B) EQU

Explanation:

The Batch if command supports numeric comparison operators including EQU, NEQ, LSS, LEQ, GTR, and GEQ.

19. Which Batch Script comparison operator means "not equal" for numeric values?

  1. NEQ
  2. NOTEQ
  3. !=
  4. DIFF

Answer: A) NEQ

Explanation:

NEQ is the numeric "not equal" comparison operator supported by the Batch if command.

20. Which keyword tests whether the previous command returned an error level equal to or greater than a specified value?

  1. status
  2. errorlevel
  3. returncode
  4. exitcode

Answer: B) errorlevel

Explanation:

The if errorlevel number condition tests the exit code returned by the preceding program or command. For this form, the condition is true when the value is equal to or greater than the specified number.

21. Which command implements iteration over a set of files or values?

  1. loop
  2. repeat
  3. for
  4. iterate

Answer: C) for

Explanation:

The for command executes a command for each item in a specified set. It can process files, directories, text strings, or ranges of values.

22. Which syntax is correct for a for loop inside a batch file?

  1. for %f in (*.txt) do echo %f
  2. for %%f in (*.txt) do echo %%f
  3. foreach %%f (*.txt) echo %%f
  4. for each %%f in (*.txt)

Answer: B) for %%f in (*.txt) do echo %%f

Explanation:

Inside a batch file, a for variable is written with two percent signs, such as %%f. At the interactive command prompt, a single percent sign is used.

23. What does for /f primarily provide?

  1. File encryption
  2. Parsing text and command output
  3. File compression
  4. Process termination

Answer: B) Parsing text and command output

Explanation:

The /f option enables the for command to parse text from files, strings, or command output according to specified parsing rules.

24. Which command transfers control to a labeled location in a batch file?

  1. jump
  2. goto
  3. label
  4. move

Answer: B) goto

Explanation:

The goto command transfers command processing to a label such as :start in the batch file.

25. How is a label defined in a batch file?

  1. label start
  2. #start
  3. :start
  4. @start

Answer: C) :start

Explanation:

A batch label begins with a colon. For example, :start defines a label that can be targeted by goto start.

26. Which command can call another batch file and return to the calling script?

  1. run
  2. call
  3. execute
  4. include

Answer: B) call

Explanation:

The call command invokes another batch program or a batch subroutine. Control returns to the calling batch file after the called batch program or subroutine completes.

27. Which command ends the current batch script or batch subroutine?

  1. stop
  2. exit
  3. quitbatch
  4. terminate

Answer: B) exit

Explanation:

The exit command can terminate the command interpreter or, with /b, terminate the current batch script or subroutine.

28. What does exit /b do when used inside a batch subroutine?

  1. Restarts the computer
  2. Returns control from the batch subroutine
  3. Deletes the batch file
  4. Closes every Command Prompt window

Answer: B) Returns control from the batch subroutine

Explanation:

exit /b exits the current batch script context or subroutine. When used in a called subroutine, control can return to the calling script.

29. Which command pauses a batch script and waits for a key press?

  1. wait
  2. pause
  3. sleep
  4. hold

Answer: B) pause

Explanation:

The pause command suspends processing of the batch program until the user presses a key.

30. Which batch parameter represents the first argument passed to a batch file?

  1. %0
  2. %1
  3. %2
  4. %A

Answer: B) %1

Explanation:

%0 represents the batch file name, while %1, %2, and so on represent arguments passed to the batch file.

31. Which batch parameter represents all command-line arguments?

  1. %*
  2. %ALL%
  3. %ARGS%
  4. %9%

Answer: A) %*

Explanation:

The special batch parameter %* represents all arguments passed to the batch file after the batch-file name.

32. Which command shifts batch parameters so that %1 receives the previous %2 value?

  1. rotate
  2. shift
  3. moveparam
  4. advance

Answer: B) shift

Explanation:

The shift command changes the positions of batch parameters. It can also be used to process more than nine arguments by shifting additional arguments into %9.

33. Which special variable contains a pseudo-random integer generated by the command shell?

  1. %RAND%
  2. %RANDOM%
  3. %RND%
  4. %NUMBER%

Answer: B) %RANDOM%

Explanation:

%RANDOM% is a dynamic command-shell variable that produces a pseudo-random integer.

34. Which variable can be used to obtain the current directory in a batch script?

  1. %PATH%
  2. %CD%
  3. %DIR%
  4. %CURRENT%

Answer: B) %CD%

Explanation:

%CD% expands to the current directory in the Command Shell.

35. Which syntax correctly enables delayed environment-variable expansion?

  1. set delayed=on
  2. setlocal enabledelayedexpansion
  3. enable !variables!
  4. cmd /delay

Answer: B) setlocal enabledelayedexpansion

Explanation:

setlocal enabledelayedexpansion enables delayed variable expansion within the localized environment. Variables can then be expanded using !variable!.

36. Why is delayed expansion useful inside certain parenthesized blocks?

  1. It changes the file extension
  2. It allows variables to be expanded at execution time using !variable!
  3. It disables all environment variables
  4. It converts batch files into executables

Answer: B) It allows variables to be expanded at execution time using !variable!

Explanation:

Normal percent expansion can occur when a compound command is parsed. Delayed expansion allows values to be expanded at execution time using exclamation marks, which is useful when a variable changes inside a loop or parenthesized block.

37. What is the purpose of setlocal?

  1. To start a network connection
  2. To localize environment changes within a batch script
  3. To create a local file
  4. To change the Windows language

Answer: B) To localize environment changes within a batch script

Explanation:

setlocal starts localization of environment-variable changes. The previous environment is restored when the corresponding endlocal is reached or the batch file ends.

38. Which command ends an environment-localization scope?

  1. localend
  2. endlocal
  3. unsetlocal
  4. restore

Answer: B) endlocal

Explanation:

endlocal ends the localization started by setlocal and restores the environment to its previous state.

39. Which command allows a batch script to present a list of single-character choices to a user?

  1. select
  2. choice
  3. menu
  4. input

Answer: B) choice

Explanation:

The choice command prompts the user to select one item from a list of single-character choices and sets ERRORLEVEL according to the selected choice.

40. What value does choice return for the first option?

  1. 0
  2. 1
  3. 2
  4. -1

Answer: B) 1

Explanation:

The first valid choice returns an ERRORLEVEL of 1, the second returns 2, and so on.

41. Which command calls a batch subroutine identified by a label?

  1. call :label
  2. goto :label
  3. run :label
  4. sub :label

Answer: A) call :label

Explanation:

With command extensions enabled, call :label invokes a labeled section as a batch subroutine. Execution can return to the calling location after the subroutine exits.

42. Which command can display the current date when used as echo %date%?

  1. %time%
  2. %date%
  3. %today%
  4. %calendar%

Answer: B) %date%

Explanation:

%date% is a dynamic command-shell variable representing the current date according to the system's regional settings.

43. Which command can display the current system time using environment-variable expansion?

  1. echo %time%
  2. echo %clock%
  3. time show
  4. print %clock%

Answer: A) echo %time%

Explanation:

%time% is a dynamic command-shell variable containing the current system time.

44. Which command sets the title of the Command Prompt window?

  1. caption
  2. windowtitle
  3. title
  4. name

Answer: C) title

Explanation:

The title command changes the title displayed by the Command Prompt window.

45. Which command is commonly used to concatenate the contents of multiple files?

  1. join
  2. merge
  3. type
  4. concat

Answer: C) type

Explanation:

The type command can output multiple files sequentially. With output redirection, this can be used to combine their contents into another file, such as type a.txt b.txt > combined.txt.

46. What does the pipe operator | do in the Windows Command Shell?

  1. Runs commands in reverse order
  2. Sends the output of one command to the input of another command
  3. Deletes the output of both commands
  4. Stores command output permanently

Answer: B) Sends the output of one command to the input of another command

Explanation:

The pipe operator | connects commands so that the standard output of the command on the left becomes input to the command on the right.

47. Which character is used as an escape character in the Windows Command Shell?

  1. \
  2. ^
  3. ~
  4. `

Answer: B) ^

Explanation:

The caret character ^ is commonly used to escape special characters in the Windows Command Shell. For example, ^& can represent a literal ampersand.

48. Consider the following batch script. What does it print?

@echo off
set name=Batch
if "%name%"=="Batch" (
    echo Match
) else (
    echo No Match
)
  1. No Match
  2. Batch
  3. Match
  4. ERROR

Answer: C) Match

Explanation:

The variable name contains Batch. After expansion, the condition becomes if "Batch"=="Batch", so the first branch executes.

49. Consider this batch script. What is printed?

@echo off
set count=1
:loop
echo %count%
set /a count+=1
if %count% LEQ 3 goto loop
  1. 1 2
  2. 1 2 3
  3. 0 1 2 3
  4. 3 only

Answer: B) 1 2 3

Explanation:

The script initially prints 1, increments the variable to 2, and loops. It then prints 2, increments to 3, and loops again. After printing 3, the value becomes 4, so the condition 4 LEQ 3 is false and the loop ends.

50. Consider the following batch script. What is the output?

@echo off
setlocal
set value=Original
setlocal
set value=Temporary
echo %value%
endlocal
echo %value%
endlocal
  1. Original followed by Original
  2. Temporary followed by Temporary
  3. Temporary followed by Original
  4. Original followed by Temporary

Answer: C) Temporary followed by Original

Explanation:

The inner setlocal creates a nested localization scope. Inside that scope, value is changed to Temporary. After the inner endlocal, the previous value, Original, is restored. The outer endlocal then ends the remaining localization scope.

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2026 www.includehelp.com. All rights reserved.