Positional Arguments
Positional arguments let you pass values to recipes without named parameters.
Basic Usage
Section titled “Basic Usage”Access arguments with {{$1}}, {{$2}}, etc.:
task greet: echo "Hello, {{$1}}!"$ jake greet WorldHello, World!Multiple Arguments
Section titled “Multiple Arguments”Access each argument by position:
task deploy: echo "Deploying {{$1}} to {{$2}}"$ jake deploy v1.0.0 productionDeploying v1.0.0 to productionAll Arguments
Section titled “All Arguments”Use {{$@}} to access all arguments at once:
task echo-all: echo "Arguments: {{$@}}"$ jake echo-all a b c dArguments: a b c dWith Named Parameters
Section titled “With Named Parameters”Positional arguments work alongside named parameters:
task deploy env="staging": echo "Deploying to {{env}} with args: {{$@}}"$ jake deploy env=production extra-flagDeploying to production with args: extra-flagForwarding to Commands
Section titled “Forwarding to Commands”Pass all arguments to another command:
task npm: npm {{$@}}$ jake npm install lodash# Runs: npm install lodashConditional Handling
Section titled “Conditional Handling”Check if arguments were provided:
task greet: @if eq("{{$1}}", "") echo "Hello, stranger!" @else echo "Hello, {{$1}}!" @endSyntax Notes
Section titled “Syntax Notes”- Use
{{$1}},{{$2}}, etc. for specific positions (1-indexed) - Use
{{$@}}for all arguments as a single string - Do not add spaces inside braces -
{{$1}}works,{{ $1 }}does not - Arguments are whitespace-separated on the command line