- Batch Script Tutorial
- Batch Script - Home
- Batch Script - Overview
- Batch Script - Environment
- Batch Script - Commands
- Batch Script - Files
- Batch Script - Syntax
- Batch Script - Variables
- Batch Script - Comments
- Batch Script - Strings
- Batch Script - Arrays
- Batch Script - Decision Making
- Batch Script - Operators
- Batch Script - DATE & TIME
- Batch Script - Input / Output
- Batch Script - Return Code
- Batch Script - Functions
- Batch Script - Process
- Batch Script - Aliases
- Batch Script - Devices
- Batch Script - Registry
- Batch Script - Network
- Batch Script - Printing
- Batch Script - Debugging
- Batch Script - Logging
- Batch Script Resources
- Batch Script - Quick Guide
- Batch Script - Useful Resources
- Batch Script - Discussion
Batch Script - Functions with Parameters
Functions can work with parameters by simply passing them when a call is made to the function.
Syntax
Call :function_name parameter1, parameter2… parametern
The parameters can then be accessed from within the function by using the tilde (~) character along with the positional number of the parameter.
Following example shows how a function can be called with parameters.
Example
@echo off SETLOCAL CALL :Display 5 , 10 EXIT /B %ERRORLEVEL% :Display echo The value of parameter 1 is %~1 echo The value of parameter 2 is %~2 EXIT /B 0
As seen in the above example, ~1 is used to access the first parameter sent to the function, similarly ~2 is used to access the second parameter.
Output
The above command produces the following output.
The value of parameter 1 is 5 The value of parameter 2 is 10
batch_script_functions.htm
Advertisements