# 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
[INFO]: Installing php81 packages
[INFO]: Setting up PHP 8.1 symlinks
[INFO]: Creating symlink for cgi
php-cgi81 /opt/remi/php81/root/usr/bin/php-cgi
[INFO]: Creating symlink for config
php-config81 /opt/remi/php81/root/usr/bin/php-config
[INFO]: Creating symlink for phpize
phpize81 /opt/remi/php81/root/usr/bin/phpize
[INFO]: Creating symlink for pecl
pecl81 /opt/remi/php81/root/usr/bin/pecl
[INFO]: Creating symlink for pear
pear81 /opt/remi/php81/root/usr/bin/pear
The expected output is
./upgrade.sh
[INFO]: Installing php81 packages
[INFO]: Setting up PHP 8.1 symlinks
[INFO]: Creating symlink for cgi
php-cgi8=
[INFO]: Creating symlink for config
php-config81
[INFO]: Creating symlink for phpize
phpize81
[INFO]: Creating symlink for pecl
pecl81
[INFO]: Creating symlink for pear
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.
config[@]
inprops
, and then use the indirect expansion to index intoconfig
throughprops
? IIRC that doesn't work,${!p[idx]}
indexes intop
first (treatingidx
as an arithmetic expression, so if it ends up resolving to strings that don't name an existing variable, it evaluates as zero, giving youp[0]
, or justp
, given how scalars and the zeroth element of arrays are the same thing)declare -n foo=config; echo "${foo[filename]}"
. I also think there's an answer about this on the site, but I didn't test now and don't have the time to search...cgi
,config
,phpize
,pecl
,pear
), each withpath
andfilename
keys, you would be better off having just two associative arrays (AKA "hashes") namedpaths
andfilenames
, each with keys cgi, config, phpize, pecl, and pear. Variable indirection is almost always a bad idea (and avoiding it is one the reasons hashes are useful). then you could just iterate over thesymlinks
array, which contains the keys for both hashes.