0

Assume that I have : .sh file having these commands :

#!/bin/bash
GIT_BRANCH="origin/release/2.4.0"
echo $GIT_BRANCH

then, I want to compute new varible from the GIT_BRANCH (operation of substring) : So,

RELEASE_VERSION=$( $GIT_BRANCH | cut -d "/" -f3)
echo $RELEASE_VERSION

But this does return message error : bad substitution

I tried many possibilities in the RELEASE_VERSION, but no result. like RELEASE_VERSION=$(echo $GIT_BRANCH | cut -d "/" -f3) RELEASE_VERSION=$("$GIT_BRANCH" | cut -d "/" -f3) and this return empty results

Paul Hodges
  • 8,723
  • 1
  • 12
  • 28
Imed
  • 31
  • 5
  • You likely have an odd branch name. Try quotes - `echo "$GIT_BRANCH"` – Paul Hodges May 06 '21 at 13:17
  • `RELEASE_VERSION=$( $GIT_BRANCH | cut -d "/" -f3)` is nonsense. With your input data for GIT_BRANCH, this would try to execute a command `origin/release/2.4.0`. You should get an error message _bash: origin/release/2.4.0: No such file or directory_ from this. Since you claim to get a different error message, I'm pretty sure that you did **not** post here the sequence of commands which you actually have tried out. – user1934428 May 06 '21 at 13:35

1 Answers1

3

You are definitelly missing an echo statement. Following code works for me just fine.

GIT_BRANCH="origin/release/2.4.0"
RELEASE_VERSION=$(echo $GIT_BRANCH | cut -d "/" -f3)
echo $RELEASE_VERSION
gjask
  • 193
  • 7
  • how about this command : `echo ${REPO_GIT}%.*` ? in fact, I want to remove the extension from the REPO_GIT string – Imed May 06 '21 at 13:25