Thursday, October 6, 2022

[SOLVED] Variable not populating in a bash script

Issue

I'm having a duh moment. I'm not getting this variable populated.

for i in ~/Ws/*.png; 
do 
  echo $i; 
  FNAME=cmd basename $i;
  echo $FNAME;
done;

I am getting the following output for example

home/Ws/BrainLearning.png
BrainLearning.png

But the last line is blank and I do not understand why. Basically $FNAME is not populated with the information I was expecting.


Solution

If your intention is to have FNAME filled with the basename of $i :

FNAME=$(basename $i)
echo "FNAME: $FNAME"


Answered By - LeGEC
Answer Checked By - Marie Seifert (WPSolving Admin)