# 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](https://olddocs.hak5.org/packet-squirrel-mark-ii/advanced-payloads) 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="https://932701053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F520JUF2JxB2RMXztRVAV%2Fuploads%2FntXmG0NTMrPXmjt6yAef%2FScreenshot%20from%202023-02-14%2010-26-22.png?alt=media&#x26;token=881911c8-8bd7-423e-823c-730962bfa864" 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](https://olddocs.hak5.org/packet-squirrel-mark-ii/advanced-payloads) 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

```
