VirtualProdigy
VirtualProdigy

Reputation: 1687

Bash sed command replace with output of a command

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

Answers (1)

komar
komar

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

Related Questions