This is somehow related to Use substituted string as a command in shell script I asked last year. That accepted answer worked nicely.
#!/usr/bin/env bash
for user in ytu
do
cd /home/${user}/H2-Data/crons
for path in "$user"_*_monthly_report.py
do
if [ -e $path ]
then
. ../../.profile
userpython=${user^^}_PYTHON
echo ${!userpython} $path
else
break
fi
done
done
This echos what I expected:
/home/ytu/anaconda3/bin/python ytu_clinic217_monthly_report.py
/home/ytu/anaconda3/bin/python ytu_clinic226_monthly_report.py
However, by simply changing ${user^^}_PYTHON
to $YTU_PYTHON
, which should be exactly the same in this case, the bash script now echos:
ytu_clinic217_monthly_report.py
ytu_clinic226_monthly_report.py
I even tried userpython=/home/ytu/anaconda3/bin/python
but that ends up the same. That said, if I echo $userpython
, I can still get /home/ytu/anaconda3/bin/python in the latter cases.
I wonder why can't userpython
be evaluated anymore by simply assigning the variable explicitly, and how can I make it right?