In GitLab CI script I wanted to
- Remove any character other then numbers and dot (.) and
- remove all the text after 2nd dot [Ex 5.6.7.8 -> 5.6] if dot exists in text.
So for that I have tried to use sed , but it's not working in GitLab Script (working on bash shell locally)
export BRANCH_NAME={$CI_COMMIT_REF_NAME} | sed 's/\.[^.]*$//' | sed 's/[^0-9.]//g'
any idea what is missing here ?
If sed is not going to work here then any other option to achieve the same?
Edit : As per @WiktorStribiżew - echo "$CI_COMMIT_REF_NAME" | sed 's/.[^.]$//' | sed 's/[^0-9.]//g' - export BRANCH_NAME=${CI_COMMIT_REF_NAME} | sed 's/.[^.]$//' | sed 's/[^0-9.]//g'
echo is working but export is not
echo "$CI_COMMIT_REF_NAME" | sed 's/\.[^.]*$//' | sed 's/[^0-9.]//g'work? Also, you probably meant${CI_COMMIT_REF_NAME}, not{$CI_COMMIT_REF_NAME}$(...). See my full answer.