Skip to main content
3 of 5
edited tags
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k

Test if there are files matching a pattern in bash

I am trying to write an if statement in bash to test whether there are any files matching a certain pattern. If there is a text file in a directory it should run a given script.

My code currently

if [ -f /*.txt ]; then ./script fi

Please give some ideas I only want to run the script if there is a .txt in the directory.

user40952
  • 477
  • 1
  • 5
  • 5