diff options
author | Philip Wittamore <philip@wittamore.com> | 2025-05-18 09:56:29 +0200 |
---|---|---|
committer | Philip Wittamore <philip@wittamore.com> | 2025-05-18 09:56:29 +0200 |
commit | 27577da287d57be67f3dc9be5e7d88430618893c (patch) | |
tree | 751d5d43e17f532b54266bce503f3286d6d64f5d | |
parent | 65e2eebbcfa34e10824447c05d3ef14f77ba583f (diff) | |
download | bashlib-27577da287d57be67f3dc9be5e7d88430618893c.tar.gz bashlib-27577da287d57be67f3dc9be5e7d88430618893c.tar.bz2 bashlib-27577da287d57be67f3dc9be5e7d88430618893c.zip |
update
-rw-r--r-- | STRINGS.html | 27 | ||||
-rw-r--r-- | STRINGS.md | 30 |
2 files changed, 0 insertions, 57 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> diff --git a/STRINGS.md b/STRINGS.md deleted file mode 100644 index 464f887..0000000 --- a/STRINGS.md +++ /dev/null @@ -1,30 +0,0 @@ -# Bash string manipulation cheatsheet - -[https://gist.github.com/magnetikonline/90d6fe30fc247ef110a1](https://gist.github.com/magnetikonline/90d6fe30fc247ef110a1) - -| **Assignment** | | -| :--- | :--- | -| Assign `value` to `variable` if `variable` is not already set, `value` is returned. <br> <br>Combine with a `:` no-op to discard/ignore return `value`. | `${variable="value"}` <br>`: ${variable="value"}` | -| **Removal** | | -| Delete shortest match of `needle` from front of `haystack`. | `${haystack#needle}` | -| Delete longest match of `needle` from front of `haystack`. | `${haystack##needle}` | -| Delete shortest match of `needle` from back of `haystack`. | `${haystack%needle}` | -| Delete longest match of `needle` from back of `haystack`. | `${haystack%%needle}` | -| **Replacement** | | -| Replace first match of `needle` with `replacement` from `haystack`. | `${haystack/needle/replacement}` | -| Replace all matches of `needle` with `replacement` from `haystack`. | `${haystack//needle/replacement}` | -| If `needle` matches front of `haystack` replace with `replacement`. | `${haystack/#needle/replacement}` | -| If `needle` matches back of `haystack` replace with `replacement`. | `${haystack/%needle/replacement}` | -| **Substitution** | | -| If `variable` not set, return `value`, else `variable`. | `${variable-value}` | -| If `variable` not set _or_ empty, return `value`, else `variable`. | `${variable:-value}` | -| If `variable` set, return `value`, else null string. | `${variable+value}` | -| If `variable` set _and_ not empty, return `value`, else null string. | `${variable:+value}` | -| **Extraction** | | -| Extract `length` characters from `variable` starting at `position`. | `${variable:position:length}` | -| Return string length of `variable`. | `${#variable}` | -| **Escaping** | | -| Single quotes inside a single quoted string. | `echo 'Don'\''t break my escape!'` | -| **Indirection** | | -| Return value of variable name held in `indirect`, else `value`. | `indirect="apple"` <br>`apple="fruit"` <br>`${!indirect-value}` | - |