0% found this document useful (0 votes)
2 views3 pages

Script Lab

The document provides a series of exercises for practicing Windows scripting using batch files. It includes tasks such as creating scripts to read user input, perform arithmetic operations, compare values, and utilize loops. Each exercise is designed to enhance understanding of scripting commands and their functionalities in a Windows environment.

Uploaded by

hohoman8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Script Lab

The document provides a series of exercises for practicing Windows scripting using batch files. It includes tasks such as creating scripts to read user input, perform arithmetic operations, compare values, and utilize loops. Each exercise is designed to enhance understanding of scripting commands and their functionalities in a Windows environment.

Uploaded by

hohoman8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

OPS102 -Windows scripting Lab

1. Type following code in note pad. Save file with extension “cmd”. Verify its functionality

@echo off

set /p NAME=Please enter your name:

echo Please to meet you, %NAME%

set /p FILE=Please enter a filename:

echo Saving your name into the file...

echo NAME=%NAME% >> %FILE%

echo Done.

2. Write windows shell script that reads two numbers and prints sum, product and division of two
numbers.

3. Try following script:


@echo off
set /p a=read first string
set /p b=read second string
if %a% equ %b% (echo same!) else echo not same

4. Write following script in a file and test.

SET /A sum=1+1

ECHO %sum%

SET /A mul=7*9

ECHO %mul%

SET /A div=9/3

ECHO %div%

SET /A assign=10

ECHO %assign%

SET /A assign+=15

ECHO %assign%

SET /A mod= 10%3

ECHO %mod%
5. Try following script

echo off

rem [Link] - compare as integers

SET /A A=11,B=2

IF %A% GTR %B% (

ECHO %A% is greater than %B%

) ELSE ECHO %A% is less than or equal to %B%

@echo off

rem [Link] - compare as strings

SET /A A=11,B=2

IF "%A%" GTR "%B%" (

ECHO %A% is greater than %B%

) ELSE ECHO %A% is less than or equal to %B%

Modify above code to read parameters from user


6. Example of If statement

@echo off

ECHO List of all arguments: %*

:start

IF "%1"=="" GOTO :done

ECHO %1

SHIFT

GOTO :start

:done

Try with the shown paramters

params-shift yellow orange red

List of all arguments: yellow orange red

yellow

orange

red
7. Example of for loop:
Create c:\ops102 directory and try following code
@echo off
FOR %%G IN (a,b,c,d,e,f,g) DO (md C:\ops102\%%G)

You might also like