Last active
May 6, 2018 11:16
-
-
Save im-samir-dev/e93cc52fd7722c3ef7e83dc37dc9bf75 to your computer and use it in GitHub Desktop.
Replace substrings by another strings and return value to first parameter of passed arguments in bash script
This file contains 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 characters
function replace_regexp() { | |
local result=$1 | |
local text=$2 | |
shift | |
shift | |
while [[ $# -gt 0 ]]; do | |
text=$(echo $text | sed -E "s/$1/$2/g") | |
shift | |
shift | |
done | |
eval $result="'$text'" | |
} | |
#replace_regexp res "This is <h1>sample</h1> text" "<\/?h1>" "--" | |
#echo "$res" |
This file contains 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 characters
function replace_string() { | |
local result=$1 | |
local text=$2 | |
shift | |
shift | |
while [[ $# -gt 0 ]]; do | |
text=${text//$1/$2} | |
shift | |
shift | |
done | |
eval $result="'$text'" | |
} | |
#replace_string res "This is <h1>sample</h1> text" "<h1>" "++" "</h1>" "--" | |
#echo "$res" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment