0

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.

1
  • you imply that you don't have something that you expect, but there is no description of what you expect. What do you want to store in FNAME ? Commented Sep 28, 2022 at 11:08

3 Answers 3

1

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

FNAME=$(basename $i)
echo "FNAME: $FNAME"
Sign up to request clarification or add additional context in comments.

Comments

0

Change

FNAME=cmd basename $i;

into

FNAME="cmd $(basename $i)";

Comments

0

Your shown code has syntax errors and I suggest running your script on shellcheck.net

However what you're attempting to do can be done using this find command as well without any loop:

find ~/Ws -name '*.png' -execdir echo {} +

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.