aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-11-07 18:51:30 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-11-07 18:51:30 +0300
commit7dc0063c8ebde5066b196591e27db8a5129b3840 (patch)
treed355240d01c2b6c7038b976068bbbd58f24a1181
parentbugfix (diff)
downloadlinux-home-7dc0063c8ebde5066b196591e27db8a5129b3840.tar.gz
linux-home-7dc0063c8ebde5066b196591e27db8a5129b3840.zip
add str_replace
-rw-r--r--%HOME%/.bash_utils/text.sh22
1 files changed, 19 insertions, 3 deletions
diff --git a/%HOME%/.bash_utils/text.sh b/%HOME%/.bash_utils/text.sh
index aefe453..47e6435 100644
--- a/%HOME%/.bash_utils/text.sh
+++ b/%HOME%/.bash_utils/text.sh
@@ -26,7 +26,23 @@ doslint() {
trim "$@" && trimdoseol "$@" && doseol "$@"
}
-replace_word() (
+str_replace() (
+ set -o errexit -o nounset -o pipefail
+
+ if [ "$#" -lt 3 ]; then
+ echo "usage: ${FUNCNAME[0]} OLD NEW PATH..." >&2
+ return 1
+ fi
+
+ local old="$1"
+ shift
+ local new="$1"
+ shift
+
+ sed --binary --in-place -- "s/$old/$new/g" "$@"
+)
+
+str_replace_word() (
set -o errexit -o nounset -o pipefail
if [ "$#" -lt 3 ]; then
@@ -101,7 +117,7 @@ str_split() (
shift
case "$key" in
-h|--help)
- echo "usage: ${FUNCNAME[0]} [-h|--help] [-z|-0] [--] STR DELIM"
+ echo "usage: ${FUNCNAME[0]} [-h|--help] [-0|-z] [--] STR DELIM"
return 0
;;
-0|-z)
@@ -123,7 +139,7 @@ str_split() (
args+=("$@")
if [ "${#args[@]}" -ne 2 ]; then
- echo "usage: ${FUNCNAME[0]} [-h|--help] [-z|-0] [--] STR DELIM"
+ echo "usage: ${FUNCNAME[0]} [-h|--help] [-0|-z] [--] STR DELIM"
return 1
fi