I'm trying to assign the results of find to a dynamic variable using the entries of an array both as the variable name and search string.
databases=(ABC DEF GHI JKL)
for i in "${databases[@]}"
do
schema_$i=$(find '/hana/shared/backup_service/backup_shr/Schema' -type d -iname ${i} -mtime 0)
done
The result should be 0 to 4 variables that look something like this (depending on how many folders were found):
schema_ABC=/hana/shared/backup_service/backup_shr/Schema/ABC
However when I try this I get 'No such file or directory' as an error.
./find_schema.sh: line 4: schema_ABC=/hana/shared/backup_service/backup_shr/Schema/ABC: No such file or directory
./find_schema.sh: line 4: schema_DEF=/hana/shared/backup_service/backup_shr/Schema/DEF: No such file or directory
./find_schema.sh: line 4: schema_GHI=: command not found
./find_schema.sh: line 4: schema_JKL=/hana/shared/backup_service/backup_shr/Schema/JKL: No such file or directory
The folder structure looks like this:
Server:/hana/shared/backup_service/backup_shr/Schema # ll
total 0
drwxr-xr-x 2 root root 0 Sep 29 2020 Test
drwxr-xr-x 2 root root 0 Jan 24 21:15 ABC
drwxr-xr-x 2 root root 0 Jan 24 21:30 DEF
drwxr-xr-x 2 root root 0 Jan 12 22:00 GHI
drwxr-xr-x 2 root root 0 Jan 24 21:45 JKL
I believe that I'm not declaring that variable correctly but I can't make out what's wrong.