Reputation: 1687
I'm working on one of my first bash scripts on mac. My goal is to read the name of my git branch, save it into the terminal variable PR_TITLE
and then finally replace the placeholder pull_request_name
with the variable $PR_TITLE
using sed -i
.
Below are the terminal commands I am running. Setting the variable is working fine but I am unable to replace the placeholder with the variable. Currently bash outputs the following when I run my sed command. -bash: feature/issues-5-6: No such file or directory
PR_TITLE=$( git branch | grep \* | tr -d '*' )
sed -i '' "s/\pull_request_name/$($PR_TITLE)/" /Users/$USER/Desktop/PR_File.txt
Upvotes: 0
Views: 3184
Reputation: 881
You use inside quote "
bash command substitution command $(command)
. To avoid this you need quote first $
.
sed -i '' "s/\pull_request_name/\$($PR_TITLE)/" /Users/$USER/Desktop/PR_File.txt
Upvotes: 2