Can't seem to access associative array with named reference in bash
0
votes
4
answers
456
views
# SETUP PHP81 SYMLINKS
declare -A cgi=([path]="/opt/remi/php81/root/usr/bin/php-cgi" [filename]="php-cgi81")
declare -A config=([path]="/opt/remi/php81/root/usr/bin/php-config" [filename]="php-config81")
declare -A phpize=([path]="/opt/remi/php81/root/usr/bin/phpize" [filename]="phpize81")
declare -A pecl=([path]="/opt/remi/php81/root/usr/bin/pecl" [filename]="pecl81")
declare -A pear=([path]="/opt/remi/php81/root/usr/bin/pear" [filename]="pear81")
declare -a symlinks=("cgi" "config" "phpize" "pecl" "pear")
echo -en "[INFO]: Setting up PHP 8.1 symlinks\n"
cd /usr/bin
for symlink in "${symlinks[@]}";
do
echo -en "[INFO]: Creating symlink for ${symlink}\n"
# Get the array that matches the string in symlink
props="$symlink[@]"
# Print out the filename property eg cgi[filename], config[filename], phpize[filename]
echo ${!props[filename]}
echo -en "\n"
done
There is the section of code giving me issues. It currently outputs
./upgrade.sh
php-cgi81 /opt/remi/php81/root/usr/bin/php-cgi
php-config81 /opt/remi/php81/root/usr/bin/php-config
phpize81 /opt/remi/php81/root/usr/bin/phpize
pecl81 /opt/remi/php81/root/usr/bin/pecl
pear81 /opt/remi/php81/root/usr/bin/pear
The expected output is
./upgrade.sh
php-cgi8=
php-config81
phpize81
pecl81
pear81
This is now solved I posted the solution below but someone down voted it because they dislike my solution but the solution I posted is working. But you decide what you want to use. Thanks for the help.
Asked by Corey Rosamond
(1 rep)
Jul 5, 2022, 04:02 PM
Last activity: Jul 6, 2022, 03:13 PM
Last activity: Jul 6, 2022, 03:13 PM