Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Variables inside <code>'</code> don't get substituted in bash. To get string substitution (or interpolation, if you're familiar with perl) you would need to change it to use double quotes <code>"</code> instead of the single quotes:</p> <pre><code>$ # enclose entire expression in double quotes $ sed "s/draw($prev_number;n_)/draw($number;n_)/g" file.txt &gt; tmp $ # or, concatenate strings with only variables inside double quotes $ # this would restrict expansion to relevant portion $ # and prevent accidental expansion for !, backticks, etc $ sed 's/draw('"$prev_number"';n_)/draw('"$number"';n_)/g' file.txt &gt; tmp $ # variable cannot contain arbitrary characters $ # see link in further reading section for details $ a='foo bar' $ echo 'baz' | sed 's/baz/'"$a"'/g' sed: -e expression #1, char 9: unterminated `s' command </code></pre> <p><br></p> <p><strong>Further Reading:</strong></p> <ul> <li><a href="https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash">Difference between single and double quotes in Bash</a> </li> <li><a href="https://stackoverflow.com/questions/29613304/is-it-possible-to-escape-regex-metacharacters-reliably-with-sed">Is it possible to escape regex metacharacters reliably with sed</a> </li> <li><a href="https://stackoverflow.com/questions/5864146/use-slashes-in-sed-replace">Using different delimiters for sed substitute command</a></li> <li>Unless you need it in a different file you can use the <a href="https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux">-i flag to change the file in place</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload