# Using Multiple shell commands with interpolation

**URL:** <https://community.jenkins.io/t/using-multiple-shell-commands-with-interpolation/11710>\
**Category:** Ask a question\
**Created:** [January 10, 2024, 3:15pm UTC](https://community.jenkins.io/t/using-multiple-shell-commands-with-interpolation/11710 "2024-01-10T15:15:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheerbuzz](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@cheerbuzz](https://community.jenkins.io/u/cheerbuzz)\
**Post date:** [January 10, 2024, 3:15pm UTC](https://community.jenkins.io/t/using-multiple-shell-commands-with-interpolation/11710/1 "2024-01-10T15:15:57Z")

</div>

Usually when executing multiple shell commands i use multiline strings:

```auto
bat """
-cmd1
-cmd2 ...
"""

```

but when using withCredentials[…]  
i have to do `bat 'cmd %credential% cmd2'` to interpolate correctly

But this gives me an error because it just sees it as one command. What is the correct way to do this?

Jenkins setup:Jenkins 2.426.1

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [January 10, 2024, 3:19pm UTC](https://community.jenkins.io/t/using-multiple-shell-commands-with-interpolation/11710/2 "2024-01-10T15:19:45Z")

</div>

```auto
bat '''
cmd %credential% 
cmd2
'''

```

but for windows batch you can also use double quotes I think as `%variable%` is not interpolated by groovy so it reaches as is the windows batch

---

<div class="post-metadata">

**Author:** ![cheerbuzz](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@cheerbuzz](https://community.jenkins.io/u/cheerbuzz)\
**Post date:** [January 10, 2024, 3:41pm UTC](https://community.jenkins.io/t/using-multiple-shell-commands-with-interpolation/11710/3 "2024-01-10T15:41:46Z")

</div>

Indeed, works. But one more question

when i defined a normal variable how do i use it in there as well?

```auto
def path = "path\\folder"
with Credentials [...] {
bat '''
cd %path%
cmd %credential% 
cmd2
'''
}

```

the path evaluates to nothing here

Yes double quotes work too but interpolate unsafely and give a warning.

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [January 10, 2024, 4:19pm UTC](https://community.jenkins.io/t/using-multiple-shell-commands-with-interpolation/11710/4 "2024-01-10T16:19:16Z")

</div>

```auto
withEnv(["path=path\\folder"]) {
  with Credentials [...] {
    bat '''
    cd %path%
    cmd %credential% 
    cmd2
    '''
  }
}

```
