0

I am trying to run the following script on a OpenSuse machine:

OUR_REPO=$(git branch | grep "*" | awk '{print $2}')
THE_REPO_THAT_OURS_IS_BASED_ON="origin/$OUR_REPO"
GIT_COMMIT=$(git merge-base $OUR_REPO $THE_REPO_THAT_OURS_IS_BASED_ON)
echo "$OUR_REPO"
echo "$THE_REPO_THAT_OURS_IS_BASED_ON"
echo "$GIT_COMMIT"

and I get the following error:

fatal: Not a valid object name release/VERSION?
release/VERSION
origin/release/VERSION

The interesting part is that, if I am running each of those commands directly into the terminal everything works properly.

Also, if I am trying to run this script via my local machine with Fedora, I don't have any kind of issue.

The command that I use to run the script: bash my_script.sh

On the OpenSuse machine, if has any importance, I am using zsh.

Does any of you know what I am doing wrong?

19
  • 1
    Do you really get the error message with the script shown in the question? The script has 6 lines while the error refers to line 8. The \r might mean that the script has DOS line endings which should be converted to UNIX line endings. Did you create the script with a Windows text editor?
    – Bodo
    Commented May 13, 2022 at 9:58
  • You also forgot to quote some of the parameter expansions. See When is double-quoting necessary? (in short, it's needed in most Bourne-like shells, less so in zsh). Commented May 13, 2022 at 9:58
  • @Bodo I've updated the error, the \r is was because of an empty line.
    – Mircea
    Commented May 13, 2022 at 10:01
  • 1
    @Mircea, there's normally no CR characters in Unix text files. If you had one in the empty line, you likely add one on every line because the file was created on Windows. Run dos2unix on the file to fix it. Commented May 13, 2022 at 10:02
  • 1
    @Mircea Please add all requested information to the question and format it properly instead of using comments for this purpose. If you fixed the errors, show the fixed script in your question.
    – Bodo
    Commented May 13, 2022 at 10:13

0

Browse other questions tagged .