Skip to content

Positional Arguments

Positional arguments let you pass values to recipes without named parameters.

Access arguments with {{$1}}, {{$2}}, etc.:

task greet:
echo "Hello, {{$1}}!"
Terminal window
$ jake greet World
Hello, World!

Access each argument by position:

task deploy:
echo "Deploying {{$1}} to {{$2}}"
Terminal window
$ jake deploy v1.0.0 production
Deploying v1.0.0 to production

Use {{$@}} to access all arguments at once:

task echo-all:
echo "Arguments: {{$@}}"
Terminal window
$ jake echo-all a b c d
Arguments: a b c d

Positional arguments work alongside named parameters:

task deploy env="staging":
echo "Deploying to {{env}} with args: {{$@}}"
Terminal window
$ jake deploy env=production extra-flag
Deploying to production with args: extra-flag

Pass all arguments to another command:

task npm:
npm {{$@}}
Terminal window
$ jake npm install lodash
# Runs: npm install lodash

Check if arguments were provided:

task greet:
@if eq("{{$1}}", "")
echo "Hello, stranger!"
@else
echo "Hello, {{$1}}!"
@end
  • 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
  • Variables - Named variable expansion
  • Tasks - Recipe parameters with defaults