Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The behavior of <code>${VARIABLE/PATTERN/REPLACEMENT}</code> depends on what shell you're using, and for bash what version. Under ksh, or under recent enough (I think ≥ 4.0) versions of bash, <code>${finalt/'&lt;/span&gt;&lt;/td&gt;'/}</code> strips that substring as desired. Under older versions of bash, the quoting is rather quirky; you need to write <code>${finalt/&lt;\/span&gt;&lt;\/td&gt;/}</code> (which still works in newer versions).</p> <p>Since you're stripping a suffix, you can use the <code>${VARIABLE%PATTERN}</code> or <code>${VARIABLE%%PATTERN}</code> construct instead. Here, you're removing everything after the first <code>&lt;/</code>, i.e. the longest suffix that matches the pattern <code>&lt;/*</code>. Similarly, you can strip the leading HTML tags with <code>${VARIABLE##PATTERN}</code>.</p> <pre><code>trimmed=${finalt%%&lt;/*}; trimmed=${trimmed##*&gt;} </code></pre> <p>Added benefit: unlike <code>${…/…/…}</code>, which is specific to bash/ksh/zsh and works slightly differently in all three, <code>${…#…}</code> and <code>${…%…}</code> are fully portable. They don't do as much, but here they're sufficient.</p> <p>Side note: although it didn't cause any problem in this particular instance, you should always put <strong>double quotes around variable substitutions</strong>, e.g.</p> <pre><code>echo "${finalt/'&lt;/span&gt;&lt;/td&gt;'/}" </code></pre> <p>Otherwise the shell will expand wildcards and spaces in the result. The simple rule is that if you don't have a good reason to leave the double quotes out, you put them.</p>
 

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