Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Saying, I have this tree and I want to execute ruby on all scripts within the folder. How could I archive through one line of command.

./
../
rb-script/
    sample1.rb
    sample2.rb
share|improve this question

2 Answers 2

up vote 8 down vote accepted

Something along the lines (depending on your shell) of

for file in rb-script/*.rb; do ruby "$file"; done

should do the trick; alternatively (and shell-independently, I think)

find rb-script -type f -exec ruby "{}" \;

using find; where you can, depending on your situation, be more specific, à la

find rb-script -maxdepth 1 -type f -name '*.rb' -exec ruby "{}" \;

In general, command <glob-pattern> would also work if command accepts several files (and there are less files than the commandline argument maximum of your shell), but I doubt ruby does that. (You could write a wrapper script such that ruby-wrapper rb-script/*.rb would do what you want, though.)

share|improve this answer
    
Thanks. Good tips for using ; to execute multiple commands. –  steveyang Mar 10 '12 at 11:11

If this will be part of a daemon, you could use the run-parts command to execute everything in the folder in alphabetical order. This command is especially useful if you need to execute it in reverse order for shutdown.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.