Shell – Matching all files ending with a certain extension with a shell glob (say, all files ending with .sh)

shell-scriptwildcards

I desire to match all files ending with a certain extension with a shell glob.

In this case I desire to target all files ending with the .sh extension, which are bourne files I execute with the Bash shell after putting a "shebang" (like #!/bin/bash) at their first line.

This is, for example, a cron command I have:

0 0 * * * "$HOME"/public_html/cron_daily/myfile.sh 2>/dev/null

Instead myfile.sh I need to target all files in that dir, ending with a .sh extension.

Is the following code correct?

0 0 * * * "$HOME"/public_html/cron_daily/*$.sh 2>/dev/null

Update

I think this is good when using a glob:

*.{sh}

Best Answer

You can't do it that way, since they will be combined into one command line.

for scr in "$HOME"/public_html/cron_daily/*.sh ; do "$scr" 2> /dev/null; done
Related Question