# Run bash commands within steps/command: instead of running script.sh

**URL:** https://forum.buildkite.community/t/run-bash-commands-within-steps-command-instead-of-running-script-sh/1857
**Category:** General
**Created:** [January 18, 2022, 4:36pm UTC](https://forum.buildkite.community/t/run-bash-commands-within-steps-command-instead-of-running-script-sh/1857 "2022-01-18T16:36:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![novak100](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@novak100](https://forum.buildkite.community/u/novak100)
#### Post date: [January 18, 2022, 4:36pm UTC](https://forum.buildkite.community/t/run-bash-commands-within-steps-command-instead-of-running-script-sh/1857/1 "2022-01-18T16:36:59Z")

</div>

Question about command:  
Is it possible to execute whole bash script from steps/command: instead of wrapping it up into a script.sh and executing as a script? (command: script.sh)  
e.g.

```auto
- label: ":yaml: RUN SCRIPT"
  command: | 
     "A=2"
     "B=3"
      if [[$A == $B]] ; then 
               echo "well done"
    - else 
             echo "nope"
    - fi

```

Reason for asking is that I would like to control few things from buildkite level instead of first pushing scripts to the repo etc

---

<div class="post-metadata">

### Author: ![jeremy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/jeremy/32/1040_2.png) [@jeremy](https://forum.buildkite.community/u/jeremy)
#### Post date: [January 18, 2022, 5:26pm UTC](https://forum.buildkite.community/t/run-bash-commands-within-steps-command-instead-of-running-script-sh/1857/2 "2022-01-18T17:26:56Z")

</div>

@novak100

Absolutely! The example you provided is pretty much exactly how you would do that. The only thing you would need to change is to fix up the syntax in your block:

```auto
  - label: ":yaml: RUN SCRIPT"
    command: |
      A=2
      B=3
      if [[\$A == \$B]] ; then
        echo "well done"
      else
        echo "nope"
      fi

```

Hope that helps!

---

<div class="post-metadata">

### Author: ![moensch](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/moensch/32/33_2.png) [@moensch](https://forum.buildkite.community/u/moensch)
#### Post date: [January 19, 2022, 7:21am UTC](https://forum.buildkite.community/t/run-bash-commands-within-steps-command-instead-of-running-script-sh/1857/3 "2022-01-19T07:21:58Z")

</div>

I always make sure I explicitly set `-e` on those in-line scripts to make sure they error if a single command fails:

```auto
command: |
  #!/bin/bash -e
  A=2
  B=3
  if [[\$A == \$B]] ; then
    echo "well done"
  else
    echo "nope"
  fi

```

---

<div class="post-metadata">

### Author: ![anon4496704](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon4496704](https://forum.buildkite.community/u/anon4496704)
#### Post date: [January 19, 2022, 7:55am UTC](https://forum.buildkite.community/t/run-bash-commands-within-steps-command-instead-of-running-script-sh/1857/4 "2022-01-19T07:55:47Z")

</div>

Thanks, @moensch for the info!

I just ran a test with some failing steps and without the `-e` set. When it reached the failing step, it immediately stopped the command step and exited. So I think `-e` is not necessary as the script is part of the command step which by nature exits when there is a failure.

Please let us know if you see different behavior.
