mirror of
https://github.com/dylanaraps/pure-sh-bible
synced 2024-06-08 16:52:31 +02:00
Merge 29be58b3fa
into 26bc7e8d6c
This commit is contained in:
commit
ade0a749c6
39
README.md
39
README.md
|
@ -175,8 +175,12 @@ without leading/trailing white-space and with truncated spaces.
|
||||||
trim_all() {
|
trim_all() {
|
||||||
# Usage: trim_all " example string "
|
# Usage: trim_all " example string "
|
||||||
|
|
||||||
# Disable globbing to make the word-splitting below safe.
|
# Save and disable the globbing state to make the word-splitting
|
||||||
set -f
|
# below safe.
|
||||||
|
case $- in
|
||||||
|
*f*) DIDGLOB=false; ;;
|
||||||
|
*) DIDGLOB=true; set -f; ;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Set the argument list to the word-splitted string.
|
# Set the argument list to the word-splitted string.
|
||||||
# This removes all leading/trailing white-space and reduces
|
# This removes all leading/trailing white-space and reduces
|
||||||
|
@ -186,8 +190,8 @@ trim_all() {
|
||||||
# Print the argument list as a string.
|
# Print the argument list as a string.
|
||||||
printf '%s\n' "$*"
|
printf '%s\n' "$*"
|
||||||
|
|
||||||
# Re-enable globbing.
|
# Re-set globbing to it's previous condition
|
||||||
set +f
|
$DIDGLOB && set +f
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -270,9 +274,12 @@ This is an alternative to `cut`, `awk` and other tools.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
split() {
|
split() {
|
||||||
# Disable globbing.
|
# Save and disable the globbing state to make the word-splitting
|
||||||
# This ensures that the word-splitting is safe.
|
# below safe.
|
||||||
set -f
|
case $- in
|
||||||
|
*f*) DIDGLOB=false; ;;
|
||||||
|
*) DIDGLOB=true; set -f; ;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Store the current value of 'IFS' so we
|
# Store the current value of 'IFS' so we
|
||||||
# can restore it later.
|
# can restore it later.
|
||||||
|
@ -296,9 +303,8 @@ split() {
|
||||||
# Restore the value of 'IFS'.
|
# Restore the value of 'IFS'.
|
||||||
IFS=$old_ifs
|
IFS=$old_ifs
|
||||||
|
|
||||||
# Re-enable globbing.
|
# Re-set globbing to it's previous condition
|
||||||
set +f
|
$DIDGLOB && set +f
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example Usage:**
|
**Example Usage:**
|
||||||
|
@ -326,9 +332,12 @@ $ split "1, 2, 3, 4, 5" ", "
|
||||||
trim_quotes() {
|
trim_quotes() {
|
||||||
# Usage: trim_quotes "string"
|
# Usage: trim_quotes "string"
|
||||||
|
|
||||||
# Disable globbing.
|
# Save and disable the globbing state to make the word-splitting
|
||||||
# This makes the word-splitting below safe.
|
# below safe.
|
||||||
set -f
|
case $- in
|
||||||
|
*f*) DIDGLOB=false; ;;
|
||||||
|
*) DIDGLOB=true; set -f; ;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Store the current value of 'IFS' so we
|
# Store the current value of 'IFS' so we
|
||||||
# can restore it later.
|
# can restore it later.
|
||||||
|
@ -355,8 +364,8 @@ trim_quotes() {
|
||||||
# Restore the value of 'IFS'.
|
# Restore the value of 'IFS'.
|
||||||
IFS=$old_ifs
|
IFS=$old_ifs
|
||||||
|
|
||||||
# Re-enable globbing.
|
# Re-set globbing to it's previous condition
|
||||||
set +f
|
$DIDGLOB && set +f
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue