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?
line 8. The\rmight 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 May 13 '22 at 09:58?inVERSION?is the\r. Are you opening/editing the file in a Windows machine? That's what is causing the problem. – terdon May 13 '22 at 10:02dos2unixon the file to fix it. – Stéphane Chazelas May 13 '22 at 10:02*withgrep "*"? Then you should usefgrepinstead. – Bodo May 13 '22 at 10:04grep "*"works OK here. In BREs,*at the start of the regexp or following\(matches itself. That's different with EREs though. – Stéphane Chazelas May 13 '22 at 10:08set -xto the beginning of a script, it would show which command it executes when it is getting an error. – BiG_NoBoDy May 13 '22 at 10:02bash -x ./the-script. Here, if editing withvimfor instance,vimwould honour the MSDOS line ending so you'd end up adding aset -x<CR>line and you'd get some obscure: invalid optiont: -error message by bash (CR moves the cursor back to the left of the screen when sent to a terminal) – Stéphane Chazelas May 13 '22 at 10:04set -xworks withzshas well (or any Bourne-like shell), but here the OP is runningbash my_script.shanyway and the shell you run that from is not relevant. – Stéphane Chazelas May 13 '22 at 10:06bash -x my_script.shOUTPUT ++ git branch `++ grep '*' ++ awk '{print $2}'++ git merge-base $'release/VERSION\r' $'origin/release/VERSION\r\r' fatal: Not a valid object name release/VERSION?
release/VERSION
origin/release/VERSION
- echo $'\r'`
– Mircea May 13 '22 at 10:07\r(CR) in your script which means you probably edited it on a Windows machine at some point. You need to remove them, which you can do withdos2unixortr -d '\r' < fileorsed 's/\r//g' file. – terdon May 13 '22 at 10:10