I'm trying to store the pathway to a website in an array, but am having trouble.
It is working in the for loop - when I echo the contents of the array, it prints correctly.
In the If/Else, though, I am trying to store a specific part of the array in another variable, and that is not working. When I echo the specific part of the array, it prints nothing.
Here is the code:
#! /bin/sh
SITES=()
i=0
for d in /var/www/sites/*/;
do (
PATHWAY=$d
SITES+=($PATHWAY)
echo "$i: $PATHWAY"
); let "i++"
done
read -p 'Enter the number of the website you want to restore. Enter "exit" to quit. ' url
if [ "$url" = "exit" ]
then
exit 0
else
RESTORE_URL=${SITES[url]}
fi
select path in /var/www/sites/*; do [...]; done
?$
onurl
. Should be:RESTORE_URL=${SITES[$url]}
. Also I guess it's not functionally any different but you should usedeclare -a SITES
instead ofSITES=()
/bin/sh
is normally a symlink to bash though. @Kimberlie, try again. Your issue is thaturl
doesn't have a$
.