Trying to replace a / in a string with another string. I tried using sed but keep getting unterminated string error in the terminal.
export REPOSITORY_R= testing-2145643/test-managed
export result=$(echo $REPOSITORY_R | sed "s/\//stage")
echo $result
CodePudding user response:
There are not enough slashes (/
) in your sed statement. Using a different regex delimiter (such as ~
) allows you to see the issue easier and to fix it:
export result=$(echo $REPOSITORY_R | sed "s~\/~stage~")
CodePudding user response:
Using sed
$ export REPOSITORY_R="testing-2145643/test-managed"
$ export result=$(echo $REPOSITORY_R | sed 's|/|&stage&|')
$ echo "$result"
testing-2145643/stage/test-managed
CodePudding user response:
If you're using bash, there's no need to drag sed into this at all. Just use the shell's parameter expansion to do the replacement:
export REPOSITORY_R=testing-2145643/test-managed
export result=${REPOSITORY_R/\//stage}
printf "%s\n" "$result" # prints testing-2145643stagetest-managed