diff options
Diffstat (limited to 'STRINGS.html')
-rw-r--r-- | STRINGS.html | 27 |
1 files changed, 0 insertions, 27 deletions
diff --git a/STRINGS.html b/STRINGS.html deleted file mode 100644 index 687456f..0000000 --- a/STRINGS.html +++ /dev/null @@ -1,27 +0,0 @@ -<h1>Bash string manipulation cheatsheet</h1> -<p><a href="https://gist.github.com/magnetikonline/90d6fe30fc247ef110a1">https://gist.github.com/magnetikonline/90d6fe30fc247ef110a1</a></p> -<p>| <strong>Assignment</strong> | | -| :--- | :--- | -| Assign <code>value</code> to <code>variable</code> if <code>variable</code> is not already set, <code>value</code> is returned. <!-- raw HTML omitted --> <!-- raw HTML omitted -->Combine with a <code>:</code> no-op to discard/ignore return <code>value</code>. | <code>${variable="value"}</code> <!-- raw HTML omitted --><code>: ${variable="value"}</code> | -| <strong>Removal</strong> | | -| Delete shortest match of <code>needle</code> from front of <code>haystack</code>. | <code>${haystack#needle}</code> | -| Delete longest match of <code>needle</code> from front of <code>haystack</code>. | <code>${haystack##needle}</code> | -| Delete shortest match of <code>needle</code> from back of <code>haystack</code>. | <code>${haystack%needle}</code> | -| Delete longest match of <code>needle</code> from back of <code>haystack</code>. | <code>${haystack%%needle}</code> | -| <strong>Replacement</strong> | | -| Replace first match of <code>needle</code> with <code>replacement</code> from <code>haystack</code>. | <code>${haystack/needle/replacement}</code> | -| Replace all matches of <code>needle</code> with <code>replacement</code> from <code>haystack</code>. | <code>${haystack//needle/replacement}</code> | -| If <code>needle</code> matches front of <code>haystack</code> replace with <code>replacement</code>. | <code>${haystack/#needle/replacement}</code> | -| If <code>needle</code> matches back of <code>haystack</code> replace with <code>replacement</code>. | <code>${haystack/%needle/replacement}</code> | -| <strong>Substitution</strong> | | -| If <code>variable</code> not set, return <code>value</code>, else <code>variable</code>. | <code>${variable-value}</code> | -| If <code>variable</code> not set <em>or</em> empty, return <code>value</code>, else <code>variable</code>. | <code>${variable:-value}</code> | -| If <code>variable</code> set, return <code>value</code>, else null string. | <code>${variable+value}</code> | -| If <code>variable</code> set <em>and</em> not empty, return <code>value</code>, else null string. | <code>${variable:+value}</code> | -| <strong>Extraction</strong> | | -| Extract <code>length</code> characters from <code>variable</code> starting at <code>position</code>. | <code>${variable:position:length}</code> | -| Return string length of <code>variable</code>. | <code>${#variable}</code> | -| <strong>Escaping</strong> | | -| Single quotes inside a single quoted string. | <code>echo 'Don'\''t break my escape!'</code> | -| <strong>Indirection</strong> | | -| Return value of variable name held in <code>indirect</code>, else <code>value</code>. | <code>indirect="apple"</code> <!-- raw HTML omitted --><code>apple="fruit"</code> <!-- raw HTML omitted --><code>${!indirect-value}</code> |</p> |