# 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:

- [Fileset Scripts](https://kb.filewave.com/books/filesets-payloads "Filesets / Payloads")
- [Custom Fields](https://kb.filewave.com/books/custom-fields/page/custom-fields "Custom Fields")
- Policy Blocker Scripts

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:

<table id="bkmrk-%C2%A0-macos%2Flinux-window" style="width:58.8889%;height:148.984px;"><tbody><tr style="height:29.7969px;background-color:rgb(251,238,184);"><td style="width:27.013%;height:29.7969px;"> </td><td style="width:21.0757%;height:29.7969px;">macOS/Linux</td><td style="width:30.8486%;height:29.7969px;">Windows Powershell</td><td style="width:20.7957%;height:29.7969px;">Windows Bat</td></tr><tr style="height:29.7969px;"><td style="width:27.013%;height:29.7969px;">First Argument</td><td style="width:21.0757%;height:29.7969px;">$1</td><td style="width:30.8486%;height:29.7969px;">`$args[0]`</td><td style="width:20.7957%;height:29.7969px;">%1</td></tr><tr style="height:29.7969px;"><td style="width:27.013%;height:29.7969px;">Second Argument</td><td style="width:21.0757%;height:29.7969px;">$2</td><td style="width:30.8486%;height:29.7969px;">`$args[1]`</td><td style="width:20.7957%;height:29.7969px;">%2</td></tr><tr style="height:29.7969px;"><td style="width:27.013%;height:29.7969px;">Third Argument</td><td style="width:21.0757%;height:29.7969px;">$3</td><td style="width:30.8486%;height:29.7969px;">`$args[2]`</td><td style="width:20.7957%;height:29.7969px;">%3</td></tr></tbody></table>

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.

<p class="callout success">Although two solutions have been supplied, zsh is recommended to stay in line with Apple's policy: [https://support.apple.com/en-gb/HT208050](https://support.apple.com/en-gb/HT208050)</p>

### 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**

```shell
#!/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**

```shell
./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:

- [https://www.oreilly.com/library/view/bash-cookbook/0596526784/ch05s07.html](https://www.oreilly.com/library/view/bash-cookbook/0596526784/ch05s07.html)
- [https://www.oreilly.com/library/view/bash-cookbook/0596526784/ch05s04.html](https://www.oreilly.com/library/view/bash-cookbook/0596526784/ch05s04.html)

That output maps to:

<table id="bkmrk-%C2%A0-description-output" style="width:64.0741%;"><tbody><tr style="background-color:rgb(251,238,184);"><td style="width:9.41704%;"> </td><td style="width:76.9058%;">Description</td><td style="width:13.6771%;">Output</td></tr><tr><td style="width:9.41704%;">$1</td><td style="width:76.9058%;">Returns first argument</td><td style="width:13.6771%;">1</td></tr><tr><td style="width:9.41704%;">$2</td><td style="width:76.9058%;">Returns second argument</td><td style="width:13.6771%;">2</td></tr><tr><td style="width:9.41704%;">$3</td><td style="width:76.9058%;">Returns nothing, no third argument</td><td style="width:13.6771%;"> </td></tr><tr><td style="width:9.41704%;">$10</td><td style="width:76.9058%;">Returns first argument, followed by the '0' character</td><td style="width:13.6771%;">10</td></tr><tr><td style="width:9.41704%;">$11</td><td style="width:76.9058%;">Returns first argument, followed by the '1' character</td><td style="width:13.6771%;">11</td></tr></tbody></table>

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**

```shell
#!/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**

```shell
./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**

```shell
#!/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**

```shell
./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.

## Related Content

- [Custom Fields](https://kb.filewave.com/books/custom-fields/page/custom-fields "Custom Fields")
- [Filesets / Payloads](https://kb.filewave.com/books/filesets-payloads "Filesets / Payloads")