Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a batch file that accepts two integers as parameters

I am just beginning to learn command line scripts, and I have an assignment for school in which the first part is to create a batch file that accepts two integers as parameters. The integers will be subsequently manipulated throughout the question, and I am not looking for any help with that. I have googled this many different ways, and cannot seem to come up with an answer. How do I begin this?

I know this is very basic to probably everyone that reads this, but I am asking you to cut me some slack, we all have to start somewhere.

like image 324
mrwienerdog Avatar asked Oct 16 '10 23:10

mrwienerdog


2 Answers

Assuming MS-DOS, you can use %1, %2, etc. for input parameters.

@ECHO OFF

SET /a INT1=%1
SET /a INT2=%2

SET /a ANSWER=INT1*INT2

ECHO %ANSWER%

PAUSE

You could then call this as:

mybatchfile.bat 2 4
like image 176
LittleBobbyTables - Au Revoir Avatar answered Oct 31 '22 09:10

LittleBobbyTables - Au Revoir


On windows, it is %1 %2

http://commandwindows.com/batch.htm

example:

@echo off

echo %1 %2

set /a v = %1
set /a v2 = %1 + 1
set /a v3 = %1 * 2

echo %v% %v2% %v3%
like image 32
nonopolarity Avatar answered Oct 31 '22 10:10

nonopolarity