# libtmux.Server.if_shell

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/server.py#L2051
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-server-if_shell/

tmux command: [`if-shell`](/en/tmux/latest/manual/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`](/en/tmux/latest/manual/if-shell/).

## Examples

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

## Parameters

- `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).

## In other ports

### Run one tmux command or another, on a shell test

- TypeScript: [`server.Server.ifShell`](/en/ts/latest/reference/server-server-ifshell/) (method)
- Go: [`tmux.Server.IfShell`](/en/go/latest/reference/tmux-server-ifshell/) (method)
- Java: [`io.github.libtmux.Shell.Shell.choose`](/en/java/latest/reference/io-github-libtmux-shell-shell-choose/) (method)
- C#: [`LibTmux.Server.IfShellAsync`](/en/csharp/latest/reference/libtmux-server-ifshellasync/) (method)
