Frage

I was writing a makefile and suppose I have the following;

FILES = file1.py \
    folder1/file2.py \
    folder2/file3.py

And I have the following for loop:

    -@for file in $(FILES); do \
           echo $${file/folder1\/}; \
    done

The above will print:

file1.py
file2.py
folder2/file3.py

The output I want is:

file1.py
file2.py
file3.py

I've looked at some documentation about shell expansion but couldn't yet find a way to deal with this. May I know how I should change the code to get the correct output? Any help will be very much appreciated.

EDIT: syntax

War es hilfreich?

Lösung

Try using echo $${file##*/}. This will give only the filename part without anything up to the last slash.

Andere Tipps

You've already accepted @Jens's shell-style answer, but I'll suggest a make-style solution:

-@for file in $(notdir $(FILES)); do \
       echo $${file}; \
done
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top