I'm trying to use the next array's elements to replace some strings in a file:
declare -a replacements=($name, $description, $date, $keywords)
By using the search terms in this array:
declare -a searchs=("a.name", "a.description", "a.date", "a.keywords")
The problem is that some variables (description
, for example) have whitespaces in them:
declare description = "My name is Jonah"
Which casuses a weird behaviour on the next piece of code:
for ((i = 0; i < ${#searchs[@]}; i++))
do
sed -i -e "s/${searchs[$i]}/${replacements[$i]}/g" "./${directory}/data.txt"
done
The for loops uses every word in the string as a replacement instead of the whole string.
Is there a way to fix this error? Thanks in advance!
declare -a replacements=("$name" "$description" "$date" "$keywords")
– jesse_b Mar 12 '20 at 17:12