# Referencing Launch Arguments in Scripts ## Description Scripts ran through FileWave have the option to supply 'Launch Arguments'. These are referenced from the script but are not included in the body of the script. 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 Often Admins feel that there is a limit of 9 'Launch Arguments' through FileWave, but the below will demonstrate this is not the case. ## Information The Launch Arguments, known as [Positional Parameters](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Positional-Parameters), are referenced as follows:
macOS/Linux | Windows Powershell | Windows Bat | |
First Argument | $1 | `$args[0]` | %1 |
Second Argument | $2 | `$args[1]` | %2 |
Third Argument | $3 | `$args[2]` | %3 |
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)
### bash and sh The following example was hoped 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 ``` However, if the character '1' was supplied as single argument the following would be observed when ran: **bash\_test.sh** ```shell ./bash_test.sh 1 1 10 11 ``` The bash and sh shells are examples which treat $10 as ${1}0, $11 as ${1}1, etc.; returning the value of $1 and then appending the additional character (0 or 1 in this example). Additional reference: - [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) As such the above output is equivalent 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 |