SBF
SBF

Reputation: 1369

makefile: want to test if any file exists (*.sh)

In a makefile I want to check if there are any .sh files and chmod them if any.

test -f !/usr/local/bin/myapp/*.sh || chmod 755 /usr/local/bin/myapp/*.sh

This is the output:

chmod: cannot access '/usr/local/bin/myapp/*.sh': No such file or directory
makefile:102: recipe for target 'install' failed
make: *** [install] Error 1

I don't like using chmod -f as I might miss other errors

Is there a way to handle this?

Upvotes: 0

Views: 212

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136435

One way is GNU find:

find /usr/local/bin/myapp/ -maxdepth 1 -type f -name "*.sh" -exec chmod 755 {} +

Upvotes: 1

Related Questions