help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sed with Variable Substitution in the command


From: Steve Matzura
Subject: Re: sed with Variable Substitution in the command
Date: Thu, 19 Sep 2024 14:28:32 -0400
User-agent: Mozilla Thunderbird Beta

I solved it by putting the entire sed command in double-quotes, not single-quotes.


On 9/19/2024 10:03 AM, Steve Matzura wrote:
Can't get any of these to work, despite reading and looking at several examples. Variable substitution has always been a problem for me because there doesn't seem to be a single hard-and-fast rule--sometimes the variable is quoted, sometimes it's wrapped in braces, sometimes the "$" is interpreted by the shell as a string positional directive ("$", "%"). All of the following fail:


sed -i 's/replace-this/$with_this_variable/'


sed -i 's/replace-this/${with_this_variable}/'


sed -i 's/replace-this/"${with_this_variable}/'


What am I missing?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]