How to more accurate detect one file is a ruby script file in linux -


i know extname rb worked.

i know linux file command worked in case.

but not accurate enough decide file ruby scripts

edit:

what want is: more accuretely amount ruby lines wrote bash shell scripts followings:

find -name '*.rb' |xargs -n100 cat |grep -v '\s*#' |wc -l 

but, in fact, wrote executable ruby scripts, , others, e.g. .rake, gemfile capfile jbuider etc ...

thanks

use ruby -c. man page:

-c    causes ruby check syntax of script , exit 

this tell if file valid ruby script without executing it. if is, print "syntax ok" stdout , exit status code 0; otherwise print syntax error stderr , exit nonzero code. (you can of course suppress messages using i/o redirection, e.g. &>/dev/null.)

of course, false positives possible (the fact file valid ruby doesn't mean intended ruby script), unlikely except short files.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -