I've a bash script that I run on Debian 11 and it worked just fine, I must move it to Ubuntu Server (probably 22.04) and now it stopped working. My script below:
BRANCHES=("master" "develop")
for BRANCH in "${BRANCHES[*]}"
do
echo Building $BRANCH
git checkout "$BRANCH"
#Code doing tasks
done
Tried also "${BRANCHES[@]}"
It gives me output:
Building ("master" "develop")
error: pathspec '("master" "develop")' did not match any file(s) known to git
I don't understand why it works fine on Debian but doesn't work on Ubuntu. My guess was that it's not executed in bash (but I've #!/bin/bash +x on top of the script).
AFAIK I cannot easy check it, because I execute this script via Jenkins shell execution and do not have SSH access to the server.
Syntax error: "(" unexpected? – terdon Jan 27 '23 at 13:36for BRANCH in "${BRANCHES[@]}"; Use@instead of*, it works for me in bash in Ubuntu. – sudodus Jan 27 '23 at 13:38for BRANCH in "${BRANCHES[*]}" ^-- SC2066 (error): Since you double quoted this, it will not word split, and the loop will only run once.– Bodo Jan 27 '23 at 13:40Building master develop. (I removed thegitcommand.) Please [edit] your question and copy&paste the complete script you ran on your system and the complete output. Of course you could (should) use a minimalized version of your script. – Bodo Jan 27 '23 at 13:49BRANCHES='("master" "develop")'(with the single quotes)? – Kusalananda Jan 27 '23 at 14:42echo $SHELLinto your script. But based on the tags, it sounds like you are running this script via Jenkins. Could you please post your whole Pipeline code or Freestyle job configuration? – jayhendren Jan 27 '23 at 17:08echo $SHELLand I got the output:/bin/bash. Yeah I run it via Jenkins, but am probably not supposed to publish the whole pipeline. I am using built-in execute shell and it the array is injected via EnvInject (it was done on previous setup the same way and worked). – Aenye_Cerbin Jan 30 '23 at 07:06EnvInjectdoes not createBRANCHESas an array but a simple string. Try to create a minimal Jenkins pipeline, that actually reproduces the problem and copy&paste the pipeline code. – Bodo Jan 30 '23 at 10:32BRANCHES="master develop"andfor BRANCH in $BRANCHES, without quotes because word-splitting is intended. Always make sure you can reproduce the problem with exactly the code shown in the question without anything else. – Bodo Jan 30 '23 at 10:53