---
title: "How to set up a command to run a bash script with variables"
description: "Setting up a command to run a bash script with variables requires using shell -c and variable definitions. The command must concatenate arguments into a single string to pass to the script correctly."
url: "https://docs.itrsgroup.com/docs/faq/geneos/4411564503057-geneos-how-to-set-up-a-command-to-run-a-bash-script-with-variables/index.html"
---
When defining the user command, you need to call shell with the `-c` option and in parenthesis declare the variable name definition followed by a space in the argument to pass to the shell script.


**Note**



The arguments in the parenthesis need to use the concatenate setting to combine them into a single string to pass to `bin/sh -c`.




The following is an example script that will echo hello followed by the `$(varname)` variable value to standard out.

```
[mmuniz@myserver tmp]$ cat /tmp/hello_variable.sh#!/bin/bashecho helloecho ${varname}
```

The following user command passes the `$(varname)` variable definition to the `/tmp/hello\_variable.sh` script

![User Command configuration](https://docscdn.itrsgroup.com/faq/images/geneos/user-command-config.png)

Command XML:

```
<command name="Echo hello variable command"><targets><target>/geneos/gateway/directory/probe/managedEntity</target></targets><userCommand><type>script</type><runLocation>netprobe</runLocation><args><arg><static>/bin/sh</static></arg><arg><concatenate>false</concatenate><static>-c</static></arg><arg><concatenate>false</concatenate><static>(varname</static></arg><arg><concatenate>true</concatenate><static>=</static></arg><arg><concatenate>true</concatenate><static>value</static></arg><arg><concatenate>true</concatenate><static> </static></arg><arg><concatenate>true</concatenate><static>/tmp/hello_variable.sh)</static></arg></args><enablePassword>true</enablePassword></userCommand></command>
```


