I want to read a string and split it into words and check if there is a space after each word. I tried the below logic however how can I know if there's a space after DATABASE_URL.
#! /bin/bash
string="/dir1/dir2/dir3/dir4/dir/5/data.sql;DATABASE_URL ;5;value;/dir1/dir2/dir3/dir4/dir5/output.sql"
IFS=';'
read -ra arr <<< "$string"
# Print each value of the array by using the loop
for val in "${arr[@]}";
do
printf "name = $val\n"
done
Output of above script:
name = /dir1/dir2/dir3/dir4/dir/5/data.sql
name = DATABASE_URL
name = 5
name = value
name = /dir1/dir2/dir3/dir4/dir5/output.sql
Help here would be much appreciated.