I am trying to assign a value from the command to a dynamic variable. But I am not getting the desired output.. I am sure something is wrong so i need experts advise.
There will be multiple files like /var/tmp/server_1, /var/tmp/server_2, /var/tmp/server_3, having different server names in each file
If you want to assing values to variables (better: to elements of an array), you can do like that (in GNUlinux/bash):
$ FILES=( $(find /var/tmp -maxdepth 1 -type f -name "server_[0-9]*" -printf %f" ") )
$ declare -A NAMES ###this opens an associative array
$ for SERVER in "${FILES[@]}"; do NAMES[$SERVER]=$(grep ssp "$SERVER"); done
If you want to print to screen the servers names, then:
$ for SERVER in "${FILES[@]}"; do echo -e "${SERVER} names are:\n${NAMES[$SERVER]}"; done
Thanks Pamu.. I got the below output adding tr so i added export in front of it
./test: line 6: SERVERS_1=ssp01 ssp02 ssp03 ssp04 : command not found
_1
./test: line 6: SERVERS_2=ssp05 ssp06 ssp07 : command not found
_2
./test: line 6: SERVERS_3=ssp08 ssp09 : command not found
_3