Referencing Launch Arguments in Scripts

Description

Scripts run by FileWave can receive Launch Arguments. The arguments are supplied by FileWave and referenced by the script, but they are not written into the script body.

They may be supplied to any of the following:

Admins sometimes assume FileWave is limited to 9 launch arguments. It is not; the shell you use determines how you reference arguments 10 and higher.

Information

Launch Arguments are positional parameters. They are referenced differently depending on the script type:

  macOS/Linux Windows Powershell Windows Bat
First Argument $1 $args[0] %1
Second Argument $2 $args[1] %2
Third Argument $3 $args[2] %3

You can add more arguments and reference each one by its position.

Considerations

Shell behavior matters most when you reference the 10th argument or higher.

Although two solutions have been supplied, zsh is recommended to stay in line with Apple's policy: https://support.apple.com/en-gb/HT208050

bash and sh

The following bash example is intended to print the first 3 positional parameters, followed by the 10th and 11th.

bash_test.sh

#!/bin/bash

echo $1
echo $2
echo $3
echo $10
echo $11

exit 0

If you pass only one argument, 1, bash treats $10 and $11 differently than many admins expect:

bash_test.sh

./bash_test.sh 1
1


10
11

The bash and sh shells treat $10 as ${1}0, $11 as ${1}1, and so on. In this example, they return the value of $1 and append the extra character.

Additional references:

That output maps to:

  Description Output
$1 Returns first argument 1
$2 Returns second argument 2
$3 Returns nothing, no third argument  
$10 Returns first argument, followed by the '0' character 10
$11 Returns first argument, followed by the '1' character 11

For bash and sh, wrap two-digit positional parameters in braces so the script references the intended argument.

The corrected script uses braces for the 10th and 11th arguments.

bash_test.sh

#!/bin/bash

echo $1
echo $2
echo $3
echo ${10}
echo ${11}

exit 0

Now when executed with 11 positional parameters, the expected output is displayed:

bash_test.sh

./bash_test.sh var1a var2b var3c var4d var5e var6f var7g var8h var9i var10j var11k
var1a
var2b
var3c
var10j
var11k

zsh

zsh handles this differently. With the same example in zsh:

zsh_test.sh

#!/bin/zsh

echo $1
echo $2
echo $3
echo $10
echo ${11}

exit 0

Given the same 11 arguments, this would output:

zsh_test.sh

./zsh_test.sh var1a var2b var3c var4d var5e var6f var7g var8h var9i var10j var11k
var1a
var2b
var3c
var10j
var11k

Unlike bash and sh, zsh treats $10 as the 10th argument and $11 as the 11th argument. zsh can use either format.

Conclusion

If a script uses 10 or more launch arguments, check the shell before troubleshooting the FileWave side. In bash or sh, use ${10}, ${11}, and the same brace pattern for later arguments. In zsh, $10 and ${10} both refer to the 10th argument.


Revision #2
Created 2023-07-02 14:58:05 UTC by Josh Levitsky
Updated 2026-06-09 12:51:28 UTC by Josh Levitsky