-
-
Save UnitedWithCode/5c6ede29463c12bb56fbd46ee34fb9c5 to your computer and use it in GitHub Desktop.
Revisions
-
magnetikonline revised this gist
Feb 14, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -86,6 +86,7 @@ </table> ## Reference - http://tldp.org/LDP/abs/html/string-manipulation.html - http://tldp.org/LDP/abs/html/parameter-substitution.html - Special characters: -
magnetikonline revised this gist
Sep 5, 2020 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,6 +76,13 @@ <td>String length of <code>variable</code></td> <td><code>${#variable}</code></td> </tr> <tr> <th colspan="2">Escaping</th> </tr> <tr> <td>Single quotes inside a single quoted string</td> <td><code>echo 'Don'\''t break my escape!'</code></td> </tr> </table> ## Reference -
magnetikonline revised this gist
Nov 26, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ <th colspan="2">Assignment</th> </tr> <tr> <td>Assign <code>value</code> to <code>variable</code> if <code>variable</code> is not already set, <code>value</code> is returned.<br /><br />Combine with a <code>:</code> no-op to discard/ignore return <code>value</code>.</td> <td><code>${variable="value"}</code><br /><code>: ${variable="value"}</code></td> </tr> <tr> -
magnetikonline revised this gist
Nov 16, 2019 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -79,6 +79,9 @@ </table> ## Reference - http://tldp.org/LDP/abs/html/string-manipulation.html - http://tldp.org/LDP/abs/html/parameter-substitution.html - Special characters: - `*`: https://www.tldp.org/LDP/abs/html/special-chars.html#ASTERISKREF - `?`: https://www.tldp.org/LDP/abs/html/special-chars.html#WILDCARDQU - http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 -
magnetikonline revised this gist
May 18, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ <th colspan="2">Assignment</th> </tr> <tr> <td>Assign <code>value</code> to <code>variable</code> if <code>variable</code> is not already set. Value will be returned.<br /><br />Couple with <code>:</code> no-op if return value is to be discarded.</td> <td><code>${variable="value"}</code><br /><code>: ${variable="value"}</code></td> </tr> <tr> -
magnetikonline revised this gist
May 18, 2018 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,13 @@ # Bash string manipulation cheatsheet <table> <tr> <th colspan="2">Assignment</th> </tr> <tr> <td>Assign <code>value</code> to <code>variable</code> if <code>variable</code> is not already set. Value will be returned. Couple with `:` no-op if return value is to be discarded.</td> <td><code>${variable="value"}</code><br /><code>: ${variable="value"}</code></td> </tr> <tr> <th colspan="2">Removal</th> </tr> -
magnetikonline revised this gist
Aug 19, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,5 +73,5 @@ ## Reference - http://tldp.org/LDP/abs/html/string-manipulation.html. - http://tldp.org/LDP/abs/html/parameter-substitution.html. - http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02. -
magnetikonline revised this gist
Apr 8, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,6 +65,10 @@ <td>Extract <code>length</code> characters from <code>variable</code> starting at <code>position</code></td> <td><code>${variable:position:length}</code></td> </tr> <tr> <td>String length of <code>variable</code></td> <td><code>${#variable}</code></td> </tr> </table> ## Reference -
magnetikonline revised this gist
Feb 22, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,11 +43,11 @@ <th colspan="2">Substitution</th> </tr> <tr> <td>If <code>variable</code> not set, return <code>value</code>, else <code>variable</code></td> <td><code>${variable-value}</code></td> </tr> <tr> <td>If <code>variable</code> not set <em>or</em> empty, return <code>value</code>, else <code>variable</code></td> <td><code>${variable:-value}</code></td> </tr> <tr> -
magnetikonline revised this gist
Feb 22, 2016 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -47,9 +47,17 @@ <td><code>${variable-value}</code></td> </tr> <tr> <td>If <code>variable</code> not set <em>or</em> empty, return <code>value</code></td> <td><code>${variable:-value}</code></td> </tr> <tr> <td>If <code>variable</code> set, return <code>value</code>, else null string</td> <td><code>${variable+value}</code></td> </tr> <tr> <td>If <code>variable</code> set <em>and</em> not empty, return <code>value</code>, else null string</td> <td><code>${variable:+value}</code></td> </tr> <tr> <th colspan="2">Extraction</th> </tr> -
magnetikonline revised this gist
Oct 22, 2015 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,6 +50,13 @@ <td>If <code>variable</code> set, return <code>value</code>, else return null string</td> <td><code>${variable+value}</code></td> </tr> <tr> <th colspan="2">Extraction</th> </tr> <tr> <td>Extract <code>length</code> characters from <code>variable</code> starting at <code>position</code></td> <td><code>${variable:position:length}</code></td> </tr> </table> ## Reference -
magnetikonline revised this gist
Oct 15, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,11 +43,11 @@ <th colspan="2">Substitution</th> </tr> <tr> <td>If <code>variable</code> not set, return <code>value</code></td> <td><code>${variable-value}</code></td> </tr> <tr> <td>If <code>variable</code> set, return <code>value</code>, else return null string</td> <td><code>${variable+value}</code></td> </tr> </table> -
magnetikonline revised this gist
Oct 15, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ </tr> <tr> <td>If <code>variable</code> set, use <code>value</code>, else use null string</td> <td><code>${variable+value}</code></td> </tr> </table> -
magnetikonline revised this gist
Oct 15, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,4 +55,4 @@ ## Reference - http://tldp.org/LDP/abs/html/string-manipulation.html. - http://www.tldp.org/LDP/abs/html/parameter-substitution.html. - http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02. -
magnetikonline created this gist
Sep 15, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ # Bash string manipulation cheatsheet <table> <tr> <th colspan="2">Removal</th> </tr> <tr> <td>Delete shortest match of <code>needle</code> from front of <code>haystack</code></td> <td><code>${haystack#needle}</code></td> </tr> <tr> <td>Delete longest match of <code>needle</code> from front of <code>haystack</code></td> <td><code>${haystack##needle}</code></td> </tr> <tr> <td>Delete shortest match of <code>needle</code> from back of <code>haystack</code></td> <td><code>${haystack%needle}</code></td> </tr> <tr> <td>Delete longest match of <code>needle</code> from back of <code>haystack</code></td> <td><code>${haystack%%needle}</code></td> </tr> <tr> <th colspan="2">Replacement</th> </tr> <tr> <td>Replace first match of <code>needle</code> with <code>replacement</code> from <code>haystack</code></td> <td><code>${haystack/needle/replacement}</code></td> </tr> <tr> <td>Replace all matches of <code>needle</code> with <code>replacement</code> from <code>haystack</code></td> <td><code>${haystack//needle/replacement}</code></td> </tr> <tr> <td>If <code>needle</code> matches front of <code>haystack</code> replace with <code>replacement</code></td> <td><code>${haystack/#needle/replacement}</code></td> </tr> <tr> <td>If <code>needle</code> matches back of <code>haystack</code> replace with <code>replacement</code></td> <td><code>${haystack/%needle/replacement}</code></td> </tr> <tr> <th colspan="2">Substitution</th> </tr> <tr> <td>If <code>variable</code> not set, use <code>fallback</code></td> <td><code>${variable-fallback}</code></td> </tr> <tr> <td>If <code>variable</code> set, use <code>value</code>, else use null string</td> <td><code>${variable-value}</code></td> </tr> </table> ## Reference - http://tldp.org/LDP/abs/html/string-manipulation.html. - http://www.tldp.org/LDP/abs/html/parameter-substitution.html. - http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02