# Shell compound commands in add\_custom\_command() possible?

**URL:** https://discourse.cmake.org/t/shell-compound-commands-in-add-custom-command-possible/4623
**Category:** Usage
**Created:** [December 8, 2021, 9:54am UTC](https://discourse.cmake.org/t/shell-compound-commands-in-add-custom-command-possible/4623 "2021-12-08T09:54:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ingolf](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/977dab/32.png) [@ingolf](https://discourse.cmake.org/u/ingolf)
#### Post date: [December 8, 2021, 9:54am UTC](https://discourse.cmake.org/t/shell-compound-commands-in-add-custom-command-possible/4623/1 "2021-12-08T09:54:30Z")

</div>

Hi,

is it possible to use [shell compound commands](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04) as `COMMAND` in `add_custom_command()`?

Stupid example (which does not work):

```auto
add_custom_command(
    OUTPUT fobar.txt
    COMMAND ( echo "foo" ; echo "bar" ) > foobar.txt
)

```

I have already tried several combinations of `COMMAND_EXPAND_LISTS`, `VERBATIM` and quoting/escaping – up to now without success (using CMake 3.21.3). Any hints?

Kind regards  
Ingolf

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 8, 2021, 10:08am UTC](https://discourse.cmake.org/t/shell-compound-commands-in-add-custom-command-possible/4623/2 "2021-12-08T10:08:54Z")

</div>

Custom commands make no guarantees about what shell they run in, if any. If you really need shell behavior, invoke a shell explicitly and pass the command to run inside it. Or better still, put it in a shell script and run that as the command.

---

<div class="post-metadata">

### Author: ![ingolf](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/977dab/32.png) [@ingolf](https://discourse.cmake.org/u/ingolf)
#### Post date: [December 8, 2021, 10:13am UTC](https://discourse.cmake.org/t/shell-compound-commands-in-add-custom-command-possible/4623/3 "2021-12-08T10:13:10Z")

</div>

Thanks a lot for the clarification.  
Ingolf
