# Escaped shell variable in pipeline config

**URL:** <https://forum.buildkite.community/t/escaped-shell-variable-in-pipeline-config/1451>\
**Category:** General\
**Created:** [February 8, 2021, 10:13am UTC](https://forum.buildkite.community/t/escaped-shell-variable-in-pipeline-config/1451 "2021-02-08T10:13:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvem](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@rvem](https://forum.buildkite.community/u/rvem)\
**Post date:** [February 8, 2021, 10:13am UTC](https://forum.buildkite.community/t/escaped-shell-variable-in-pipeline-config/1451/1 "2021-02-08T10:13:14Z")

</div>

Hi,  
I want to have a string with escaped shell variable passed as an option to some executable in the pipeline, consider the  
following example:  
`binary --pattern "\$1 == \"On network\" || \$NF == \"On network\" || \$0 ~ /.On network./"`

However, I cannot find a way to escape `$` and preserve a backslash before it. Both `\$$` and `\\$` in the pipeline configuration doesn’t seem to work. Is there a way to do such a thing?

---

<div class="post-metadata">

**Author:** ![juanitofatas](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/juanitofatas/32/957_2.png) [@juanitofatas](https://forum.buildkite.community/u/juanitofatas)\
**Post date:** [February 9, 2021, 6:58am UTC](https://forum.buildkite.community/t/escaped-shell-variable-in-pipeline-config/1451/2 "2021-02-09T06:58:45Z")

</div>

Hi Roman,

I think there is one missing `\` from `\$$` for this to work:

```
binary --pattern "\\$$1 == \"On network\" || \\$$NF == \"On network\" || \\$$0 ~ /.On network./"

```

Please let me know if that does not do it!

Cheers,  
Juanito

---

<div class="post-metadata">

**Author:** ![rvem](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@rvem](https://forum.buildkite.community/u/rvem)\
**Post date:** [February 10, 2021, 11:06am UTC](https://forum.buildkite.community/t/escaped-shell-variable-in-pipeline-config/1451/3 "2021-02-10T11:06:19Z")

</div>

I’ve tried `"\\$$1 == \"On network\" || \\$$NF == \"On network\" || \\$$0 ~ /.On network./"` as well, and looks like it evaluates to:  
`--pattern "\\$1 == \"On network\" || \\$NF == \"On network\" || \\$0 ~ /.On network./"`, which is still invalid:(

---

<div class="post-metadata">

**Author:** ![rvem](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@rvem](https://forum.buildkite.community/u/rvem)\
**Post date:** [February 11, 2021, 10:51am UTC](https://forum.buildkite.community/t/escaped-shell-variable-in-pipeline-config/1451/4 "2021-02-11T10:51:54Z")

</div>

Using single quotes instead of double seems to remove the necessity to escape `$` and `"`, so  
the following works:

```auto
--pattern '\$1 == "On network" || \$NF == "On network" || \$0 ~ /.On network./'

```

---

<div class="post-metadata">

**Author:** ![anon57234190](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@anon57234190](https://forum.buildkite.community/u/anon57234190)\
**Post date:** [February 11, 2021, 10:15pm UTC](https://forum.buildkite.community/t/escaped-shell-variable-in-pipeline-config/1451/5 "2021-02-11T22:15:23Z")

</div>

wonderful!!! I was off digging for a solution but you beat me to it!
