Making a Bamboo Script execute using /bin/bash
Asked by dustingooding:

I need to run a script using /bin/bash instead of /bin/sh, but I'm not seeing a way to do that.

In the logs, I see that /bin/sh is used to execute my script. In my script, I print out the $SHELL variable, and nothing shows up on the screen. So, I assume it's /bin/sh that's being used to run the script... but I can't confirm it. Putting #!/bin/bash at the top of my script doesn't help.

The reason I need to use /bin/bash is that a process I need to start requires a set of environment variables to be set using a an inline function (e.g., source \`rosstack find orocos_toolchain\`/env.sh) but I don't believe /bin/sh supports that, or the source call.


Answers:
author: Colin Goudie
body: You should be able to add a new builder from the builders admin menu {URL}/admin/agent/viewBuilders.action

e.g. on our Bamboo instance our Bash builder uses /bin/bash

comments: author: JulioAmerica
body: Good Day

I currently have this problem and not sure where to find this builders admin menu. Our system actually runs on bin\\ksh but bin\\bash will do for this instance as we just need a script to run

Could you possibly send a screenshot.

I am using Bamboo:

Bamboo version information  
Version5.11.1.1  
Build number51117  
Build date 4/28/16

Please help


author: John Gill
body: In Bamboo 6.1 you can add a script command and have it run in sh or bash or ps.

Not sure if this helps since you're on 5.11   

The solution above was for Bamboo Cloud.


author: Jonathan Loesch
body: The accepted answer works if you are running a "command" task from bamboo (i.e. execute a script file).

If you are trying to run a "script" task, which is just running an inline script, you can try putting this snippet at the top to force it to execute in bash. It's a hack, but it worked for me:  

```
#!/bin/bashif [ "$(ps -p "$$" -o comm=)" != "bash" ]; then    # Taken from http://unix-linux.questionfor.info/q_unix-linux-programming_85038.html    bash "$0" "$@"    exit "$?"fi
```

comments: author: samfulton
body: Champion! worked for me


author: Jerry Henley
body: Very nice! Thanks!


author: Kevin Ross
body: Woohoo! Thanks. You would expect this to be simpler with bamboo....Atlassian, are you listening?


author: Frank Weindel
body: No. Atlassian has no time for small fundamental details


author: Frank Weindel
body: This really sucks when you have to bootstrap it in 30 different script tasks.


author: ABA
body: I was able to achieve this by adding below to my script itself

#!/bin/bash


author: JulioAmerica
body: Tried this but did not work for me


author: Aaron Yang
body: Doesn't work, my Bamboo version is 6.9.2.


author: Jurgen Schober
body: if you use git/sh use

```
#!C:\PROGRA~1\Git\bin\sh.exe
```

in your shebang line (first line in inline script)

It's an absolute path. You can run any interpreter this way (cygwin/mingw). Please note: no spaces in the file name!


author: Cintia Calvo
body: In Bamboo \< 5.13, on the agents, if the non-login shell is bash, it should work adding the she-bang on script tasks.

You can achieve that by linking /bin/sh to /bin/bash, instead of /bin/dash or whatever.

From 5.13, it should work regardless of your non-login shell.

<https://confluence.atlassian.com/bamboo/bamboo-5-13-release-notes-829057609.html>

comments: author: JulioAmerica
body: How can I achieve this without upgrading.

Currently running:

Bamboo version information  
Version5.11.1.1  
Build number51117  
Build date4/28/16