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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
2












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






share|improve this question





















  • I thought “You’d just use *.sh to match all files with a .sh extension.” was clear enough... *.sh is the glob you use to match files ending with .sh.
    – Stephen Kitt
    Jul 11 at 21:03














up vote
1
down vote

favorite
2












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






share|improve this question





















  • I thought “You’d just use *.sh to match all files with a .sh extension.” was clear enough... *.sh is the glob you use to match files ending with .sh.
    – Stephen Kitt
    Jul 11 at 21:03












up vote
1
down vote

favorite
2









up vote
1
down vote

favorite
2






2





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






share|improve this question













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








share|improve this question












share|improve this question




share|improve this question








edited Jul 11 at 19:57
























asked Jul 11 at 17:38









user9303970

116223




116223











  • I thought “You’d just use *.sh to match all files with a .sh extension.” was clear enough... *.sh is the glob you use to match files ending with .sh.
    – Stephen Kitt
    Jul 11 at 21:03
















  • I thought “You’d just use *.sh to match all files with a .sh extension.” was clear enough... *.sh is the glob you use to match files ending with .sh.
    – Stephen Kitt
    Jul 11 at 21:03















I thought “You’d just use *.sh to match all files with a .sh extension.” was clear enough... *.sh is the glob you use to match files ending with .sh.
– Stephen Kitt
Jul 11 at 21:03




I thought “You’d just use *.sh to match all files with a .sh extension.” was clear enough... *.sh is the glob you use to match files ending with .sh.
– Stephen Kitt
Jul 11 at 21:03










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










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





share|improve this answer





















  • I believe it isn't a great deal but writing file instead scr could be clearer and more accurate as it is a file containing a script. What do you think?
    – user9303970
    Jul 14 at 23:02

















up vote
4
down vote













You’d just use *.sh to match all files with a .sh extension. (Adding the path as appropriate.)



However this won’t have the result you’re after. Look at run-parts to run multiple scripts from cron:



0 0 * * * /usr/bin/run-parts "$HOME"/public_html/cron_daily/ 2>/dev/null


(This will run all executables in .../public_html/cron_daily, not just .sh files. By the way, are you sure it’s a good idea to keep cron scripts under public_html? Is that directory being served by your web server?)






share|improve this answer





















  • I think only website directories are served from that directory but maybe not.
    – user9303970
    Jul 11 at 17:45











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454749%2fmatching-all-files-ending-with-a-certain-extension-with-a-shell-glob-say-all-f%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










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





share|improve this answer





















  • I believe it isn't a great deal but writing file instead scr could be clearer and more accurate as it is a file containing a script. What do you think?
    – user9303970
    Jul 14 at 23:02














up vote
1
down vote



accepted










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





share|improve this answer





















  • I believe it isn't a great deal but writing file instead scr could be clearer and more accurate as it is a file containing a script. What do you think?
    – user9303970
    Jul 14 at 23:02












up vote
1
down vote



accepted







up vote
1
down vote



accepted






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





share|improve this 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






share|improve this answer













share|improve this answer



share|improve this answer











answered Jul 11 at 17:40









Ignacio Vazquez-Abrams

31.9k66680




31.9k66680











  • I believe it isn't a great deal but writing file instead scr could be clearer and more accurate as it is a file containing a script. What do you think?
    – user9303970
    Jul 14 at 23:02
















  • I believe it isn't a great deal but writing file instead scr could be clearer and more accurate as it is a file containing a script. What do you think?
    – user9303970
    Jul 14 at 23:02















I believe it isn't a great deal but writing file instead scr could be clearer and more accurate as it is a file containing a script. What do you think?
– user9303970
Jul 14 at 23:02




I believe it isn't a great deal but writing file instead scr could be clearer and more accurate as it is a file containing a script. What do you think?
– user9303970
Jul 14 at 23:02












up vote
4
down vote













You’d just use *.sh to match all files with a .sh extension. (Adding the path as appropriate.)



However this won’t have the result you’re after. Look at run-parts to run multiple scripts from cron:



0 0 * * * /usr/bin/run-parts "$HOME"/public_html/cron_daily/ 2>/dev/null


(This will run all executables in .../public_html/cron_daily, not just .sh files. By the way, are you sure it’s a good idea to keep cron scripts under public_html? Is that directory being served by your web server?)






share|improve this answer





















  • I think only website directories are served from that directory but maybe not.
    – user9303970
    Jul 11 at 17:45















up vote
4
down vote













You’d just use *.sh to match all files with a .sh extension. (Adding the path as appropriate.)



However this won’t have the result you’re after. Look at run-parts to run multiple scripts from cron:



0 0 * * * /usr/bin/run-parts "$HOME"/public_html/cron_daily/ 2>/dev/null


(This will run all executables in .../public_html/cron_daily, not just .sh files. By the way, are you sure it’s a good idea to keep cron scripts under public_html? Is that directory being served by your web server?)






share|improve this answer





















  • I think only website directories are served from that directory but maybe not.
    – user9303970
    Jul 11 at 17:45













up vote
4
down vote










up vote
4
down vote









You’d just use *.sh to match all files with a .sh extension. (Adding the path as appropriate.)



However this won’t have the result you’re after. Look at run-parts to run multiple scripts from cron:



0 0 * * * /usr/bin/run-parts "$HOME"/public_html/cron_daily/ 2>/dev/null


(This will run all executables in .../public_html/cron_daily, not just .sh files. By the way, are you sure it’s a good idea to keep cron scripts under public_html? Is that directory being served by your web server?)






share|improve this answer













You’d just use *.sh to match all files with a .sh extension. (Adding the path as appropriate.)



However this won’t have the result you’re after. Look at run-parts to run multiple scripts from cron:



0 0 * * * /usr/bin/run-parts "$HOME"/public_html/cron_daily/ 2>/dev/null


(This will run all executables in .../public_html/cron_daily, not just .sh files. By the way, are you sure it’s a good idea to keep cron scripts under public_html? Is that directory being served by your web server?)







share|improve this answer













share|improve this answer



share|improve this answer











answered Jul 11 at 17:39









Stephen Kitt

139k22296359




139k22296359











  • I think only website directories are served from that directory but maybe not.
    – user9303970
    Jul 11 at 17:45

















  • I think only website directories are served from that directory but maybe not.
    – user9303970
    Jul 11 at 17:45
















I think only website directories are served from that directory but maybe not.
– user9303970
Jul 11 at 17:45





I think only website directories are served from that directory but maybe not.
– user9303970
Jul 11 at 17:45













 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454749%2fmatching-all-files-ending-with-a-certain-extension-with-a-shell-glob-say-all-f%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay