mirror of
https://github.com/dylanaraps/pure-sh-bible
synced 2024-05-03 22:23:13 +02:00
docs: update
This commit is contained in:
parent
4011d6482b
commit
32e27e1f84
18
README.md
18
README.md
|
@ -139,7 +139,15 @@ removing it from the start and end of the string.
|
|||
```sh
|
||||
trim_string() {
|
||||
# Usage: trim_string " example string "
|
||||
|
||||
# Remove all leading white-space.
|
||||
# '${1%%[![:space:]]*}': Strip everything but leading white-space.
|
||||
# '${1#${XXX}}': Remove the white-space from the start of the string.
|
||||
trim=${1#${1%%[![:space:]]*}}
|
||||
|
||||
# Remove all trailing white-space.
|
||||
# '${trim##*[![:space:]]}': Strip everything but trailing white-space.
|
||||
# '${trim#${XXX}}': Remove the white-space from the end of the string.
|
||||
trim=${trim%${trim##*[![:space:]]}}
|
||||
|
||||
printf '%s\n' "$trim"
|
||||
|
@ -169,9 +177,19 @@ without leading/trailing white-space and with truncated spaces.
|
|||
# shellcheck disable=SC2086,SC2048
|
||||
trim_all() {
|
||||
# Usage: trim_all " example string "
|
||||
|
||||
# Disable globbing to make the word-splitting below safe.
|
||||
set -f
|
||||
|
||||
# Set the argument list to the word-splitted string.
|
||||
# This removes all leading/trailing white-space and reduces
|
||||
# all instances of multiple spaces to a single (" " -> " ").
|
||||
set -- $*
|
||||
|
||||
# Print the argument list as a string.
|
||||
printf '%s\n' "$*"
|
||||
|
||||
# Re-enable globbing.
|
||||
set +f
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue