# Escaping $ in add\_custom\_command

**URL:** https://discourse.cmake.org/t/escaping-in-add-custom-command/5807
**Category:** Code
**Created:** [June 6, 2022, 6:55pm UTC](https://discourse.cmake.org/t/escaping-in-add-custom-command/5807 "2022-06-06T18:55:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mario\_Not64](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mario_not64/32/1478_2.png) [@Mario\_Not64](https://discourse.cmake.org/u/Mario_Not64)
#### Post date: [June 6, 2022, 6:55pm UTC](https://discourse.cmake.org/t/escaping-in-add-custom-command/5807/1 "2022-06-06T18:55:25Z")

</div>

Hello,

This is a simplied case:

add\_custom\_comand(  
COMMAND ls $(echo -l)  
VERBATIM  
)

In the real case VERBATIM is required because the COMMAND has lots of other arguments that requires it. Because of VERBATIM, the $ is getting escaped. The command becomes  
ls $(echo -l) , which does not work as I’m expecting the shell to remplace $(echo -l) with -l.

Suggestions? Thanks.

- Mario

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [June 6, 2022, 7:11pm UTC](https://discourse.cmake.org/t/escaping-in-add-custom-command/5807/2 "2022-06-06T19:11:18Z")

</div>

I would suggest not doing this. This shell command will not work on Windows, and $() rules can differ between Unixes.

If you need to do any complex operations, i would write a separate script to be the command executed - I commonly use either python or cmake scripts for this purpose.

---

<div class="post-metadata">

### Author: ![Mario\_Not64](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mario_not64/32/1478_2.png) [@Mario\_Not64](https://discourse.cmake.org/u/Mario_Not64)
#### Post date: [June 6, 2022, 7:19pm UTC](https://discourse.cmake.org/t/escaping-in-add-custom-command/5807/3 "2022-06-06T19:19:23Z")

</div>

It’s linux only and I have no portability concern. I wanted to avoid writing a separate script because the parsing of the arguments by the original command is non standard and quite messy. I wanted to avoid having to reproduce it. But seems like I will have to do it.

Thanks.
