[darcs-users] Re: execute permission for scripts

Ralph Corderoy ralph at inputplus.co.uk
Fri Nov 26 13:47:39 UTC 2004


Hi kzm,

> Ralph Corderoy <ralph at inputplus.co.uk> writes:
> > Good idea.  Is it worth checking just the magic word instead though
> > as it won't match /^#!/ elsewhere in the file.
> >
> >     find . -type f -print |
> >     while read f; do
> >         test "`
> >             dd if=$f bs=2 count=1 2>/dev/null |
> >             tr -c '#!' xx;
> >             echo
> >         `" = '#!' &&
> >         echo $f
> >     done |
> >     xargs chmod a+x
> 
> Isn't it simpler to do:
> 
>     for a in `find bin -type f -print`; do
>         if head -n 1 $a | grep -q '^#\!'; then chmod +x $a; fi
>     done

I was trying to be portable.  Some commands, typically non-GNU, don't
like binary data when expecting text.

> But if you want to do this, why not use 'file', and grep for the
> string "executable" (which seems to be included for executable
> scripts)? 

Isn't `executable' used for non-scripts too?  I'd considered file(1),
and also supplying my own magic file, but again portability was an
issue.

Cheers,


Ralph.





More information about the darcs-users mailing list