I've written a deployment plan in Bamboo, which runs all the scripts on an agent using sh, and since those agents run ubuntu 14.04 that equates to dash.
I want to do the following step:
rm -rf !(${bamboo.scripts_folder})
This should remove all the files/folders except the ones in the variable.
This works fine in bash, but when i run this in dash it gives me:
dash: 2: Syntax error: "(" unexpected
I tried running the following at the start of the script to force it to run as bash instead:
if [ "$(ps -p "$$" -o comm=)" != "bash" ]; then
bash "$0" "$@"
exit "$?"
fi
While that seems to have worked for me in the past, in this case for some reason, it doesn't appear to, as I get:
line 8: syntax error near unexpected token `('
I tried updating my script to read:
#!/bin/bash
echo "Early $0"
if [ "$(ps -p "$$" -o comm=)" != "bash" ]; then
bash "$0" "$@"
exit "$?"
fi
echo "Later $0"
rm -rf !(${bamboo.scripts_folder})
I was hoping that the echo statements would print out the shell that was currently running, but instead I get:
11-Apr-2017 13:51:25 Early /home/bamboo/bamboo-agent-home/temp/49020935-118947854-118064182-ScriptBuildTask-740980554529016045.sh
11-Apr-2017 13:51:25 Early /home/bamboo/bamboo-agent-home/temp/49020935-118947854-118064182-ScriptBuildTask-740980554529016045.sh
11-Apr-2017 13:51:25 Later /home/bamboo/bamboo-agent-home/temp/49020935-118947854-118064182-ScriptBuildTask-740980554529016045.sh
11-Apr-2017 13:51:25 /home/bamboo/bamboo-agent-home/temp/49020935-118947854-118064182-ScriptBuildTask-740980554529016045.sh: line 13: syntax error near unexpected token `('
11-Apr-2017 13:51:25 /home/bamboo/bamboo-agent-home/temp/49020935-118947854-118064182-ScriptBuildTask-740980554529016045.sh: line 13: `rm -rf !(font)'
This didn't give me anything more to go on. Can anyone suggest the "right" way to run this using dash? Or the "right" way to make this execute using bash instead of dash (note that bamboo launches everything as sh and you can't change that)