# libtmux.Server.if_shell

- **Module:** libtmux.Server
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/server.py#L2054
- **Page:** https://libtmux.org/reference/py/libtmux-server-if_shell/

```
libtmux.Server.if_shell(self, shell_command: str, tmux_command: str, else_command: str | None = None, background: bool | None = None, target_pane: str | None = None) -> None
```

Execute a tmux command conditionally via ``$ tmux if-shell``.

## Parameters

- `self`
- `shell_command` (str) — Shell command whose exit status determines which tmux command runs.
- `tmux_command` (str) — Tmux command to run if *shell_command* succeeds (exit 0).
- `else_command` (str | None) — Tmux command to run if *shell_command* fails (non-zero exit).
- `background` (bool | None) — Run the shell command in the background (``-b`` flag).
- `target_pane` (str | None) — Target pane for format expansion (``-t`` flag).

## Example

```python
>>> server.if_shell('true', 'set -g @if_test yes')
>>> server.cmd('show-options', '-gv', '@if_test').stdout[0]
'yes'
```
