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
您可以使用内部引号"
bash命令替换命令$(command)
。要避免这种情况,您需要先引号$
。
sed -i '' "s/\pull_request_name/\$($PR_TITLE)/" /Users/$USER/Desktop/PR_File.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.