Passing Arguments to Batch and Bash Scripts

Windows Batch Script

//windows-script.bat
set firstArgument=%1%
set secondArgument=%2%

echo You passed first %firstArgument% and second %secondArgument%

Usage:

.\windows-script.bat "little donald" "had a farm"

Unix Bash Script

//unix-script.bash
##!/bin/sh
firstArgument=$1
secondArgument=$2

echo You passed first $firstArgument and second $secondArgument

## to give a default value to the argument
arg="${1:-DEFAULT_VALUE}"

Usage:

bash unix-script.bash "little donald" "had a farm"

Default values: Use ${1:-DEFAULT_VALUE} syntax to provide fallback when no argument is passed.