> For the complete documentation index, see [llms.txt](https://documentation.hak5.org/packet-squirrel-mark-ii/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.hak5.org/packet-squirrel-mark-ii/payload-development/duckyscript-for-packet-squirrel/switch.md).

# SWITCH

The `SWITCH` command returns the current position of the sliding switch.

Advanced payloads can use this to determine user input.

This **does not** necessarily reflect the switch position **when the Packet Squirrel was booted**, only the **current** position of the switch.

## Return values

When called with a timeout, the `SWITCH` script will return the position of the switch (`switch1` through `switch4`).

To learn how to write payloads which can handle responses, check the [Advanced Bash](/packet-squirrel-mark-ii/advanced-payloads.md) section!

## Experimenting

You can experiment using the `SWITCH` command live, either in the Web Shell in the web UI, or via `ssh`!

<figure><img src="/files/adqzTPZ7KObsgg1lN8MC" alt=""><figcaption><p>Example of the SWITCH command in the Web Shell</p></figcaption></figure>

## Examples

Payloads using the `SWITCH` command must handle the output; for example the following payload sets the LED based on the switch position.  For more information about writing advanced payloads, see the [Advanced Bash](/packet-squirrel-mark-ii/advanced-payloads.md) section!

```bash
#!/bin/bash

# Title: Switch Demo
# 
# Description: Set the LED color based on the position of the switch.

NETMODE NAT

SP=$(SWITCH)

case $SP in
        "switch1")
                LED R SINGLE
                ;;
        "switch2")
                LED B SINGLE
                ;;
        "switch3")
                LED G SINGLE
                ;;
        "switch4")
                LED W SINGLE
                ;;
esac

```
