Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  85] [ 0]  / answers: 1 / hits: 108620  / 2 Years ago, thu, june 23, 2022, 6:55:04

I would like to replace $fileWithPath in $file, however this doesn't work because (I think) path is not escaped. How to escape it?



sed -i 's/${fileWithPath}/HAHA/g' $file

More From » bash

 Answers
5
sed -i 's|'$fileWithPath'|HAHA|g' file


Single quotes define a string literal. Putting the variable outside the literal allows the shell to expand that part.



Also: if you are going to parse paths, use a delimiter in the sed command that doesn't confuse with the directory delimiter "/".


[#42229] Friday, June 24, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cupwire

Total Points: 365
Total Questions: 126
Total Answers: 125

Location: Malaysia
Member since Thu, Feb 16, 2023
1 Year ago
cupwire questions
;