2019-09-19 09:36:16 +02:00
|
|
|
# pure sh bible
|
|
|
|
|
|
|
|
A collection of pure POSIX `sh` alternatives to external processes
|
|
|
|
|
|
|
|
|
|
|
|
## Table of Contents
|
|
|
|
|
|
|
|
<!-- vim-markdown-toc GFM -->
|
|
|
|
|
2019-09-19 09:56:28 +02:00
|
|
|
* [STRINGS](#strings)
|
|
|
|
* [Strip pattern from start of string](#strip-pattern-from-start-of-string)
|
|
|
|
* [Strip pattern from end of string](#strip-pattern-from-end-of-string)
|
|
|
|
|
2019-09-19 09:36:16 +02:00
|
|
|
<!-- vim-markdown-toc -->
|
2019-09-19 09:56:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
# STRINGS
|
|
|
|
|
|
|
|
## Strip pattern from start of string
|
|
|
|
|
|
|
|
**Example Function:**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
lstrip() {
|
|
|
|
# Usage: lstrip "string" "pattern"
|
|
|
|
printf '%s\n' "${1##$2}"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
**Example Usage:**
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ lstrip "The Quick Brown Fox" "The "
|
|
|
|
Quick Brown Fox
|
|
|
|
```
|
|
|
|
|
|
|
|
## Strip pattern from end of string
|
|
|
|
|
|
|
|
**Example Function:**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
rstrip() {
|
|
|
|
# Usage: rstrip "string" "pattern"
|
|
|
|
printf '%s\n' "${1%%$2}"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
**Example Usage:**
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ rstrip "The Quick Brown Fox" " Fox"
|
|
|
|
The Quick Brown
|
|
|
|
```
|