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

Positional args ({{$1}}, {{$2}}) do not work inside @if condition expressions. Condition strings are not pre-expanded, so eq("{{$1}}", "") looks up a variable literally named $1 (not found), always resolves to empty string, and makes the condition useless.

Use named parameters instead. Named parameters are stored in the variables map and work correctly with all condition functions:

# Works: named parameter used in condition
task greet name="stranger":
@if eq(name, stranger)
echo "No name given, using default"
@else
echo "Hello, {{name}}!"
@end
Terminal window
$ jake greet
No name given, using default
$ jake greet name=Alice
Hello, Alice!

Named parameters also support eq(), neq(), exists(), and any other condition function.

  • 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