file * | grep executable | awk -F":" {print $1} | chmod 755
How do I get chmod to interprete the result from the pipe?
I know this can probably be done with find or something, but I've had
several similiar cases before...
J-P
--- Remove "no" from my mail-adress to reply. ---
You can use the xargs command:
file * | grep executable | awk -F":" {print $1} | xargs chmod 755
Mark
--
Real Name: Mark Mraz
Email Address: mm...@rpa.net
Web Page: http://www2.rpa.net/~mmraz
chmod expects the filenames to be in its argument list, not standard
input. You can use xargs or `` substitution:
file * | grep executable | awk -F":" '{print $1}' | xargs chmod 755
chmod 755 `file * | grep executable | awk -F":" '{print $1}'`
BTW, awk has built-in regexp matching, so you don't need to use grep:
file * | awk -F":" '/executable/ {print $1}'
--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.
On at least some Unix variants there is an X permission which does
exactly what you want:
chmod -R a+rX,go-w .
So no pipes are needed. Check out the chmod man page.
Bob
--
======================================================================
Bob Vickers R.Vi...@rhbnc.ac.uk
Dept of Computer Science, Royal Holloway College, University of London
WWW: http://www.cs.rhbnc.ac.uk/home/bobv
Phone: +44 1784 443691
Try this:
file * | grep executable | awk -F":" {print $1} | xargs chmod 755
You might also consider just doing chmod a+x which will add execute
permission but won't change the existing read/write permissions (unless,
of course, you actually WANT to change them to 755).
--
Allen Kirby
AT&T Information Technology Services
Alpharetta, GA.
The views expressed here are mine, not my employers.
U can't really pipe to chmod, because chmod does not expect any input
from the stdin. You may want to use `<unix-cmd>` ie any unix command
within ` characters, would replace itself with the output of that
command.
For eg., echo `pwd`
wud echo the output of the pwd command.
So chmod ... `unix-cmd-to-get-whatever-file-names-u-want'
wud do what u want.
#set -x # uncomment to observe evaluation of constructed chmod commands
eval `file * |
sed -n '/executable/{
s/:.*$//
s/^/chmod 755 /
# the following line shouldn't be necessary, but I found
# that my sed doesn't print newlines given the "n" option
# If yours works per manual, the below shouldn't break it
s/$/;/p
}'
`
set +x
You could also have used the "xargs" command (see man page), but
having combined the grep and awk pass into one sed command, one
might as well use the regular expression capabilities of sed to
also construct the entire command line, and evaluate that through
the "eval" builtin.
P.S. Note that, unlike a "find" command, the above will _not_ descend
into subdirectories.
P.P.S. Alert readers will see that since the "chmod" command is
executed once per applicable executable filename, there will be
_more_ processes used than will a single constructed line of one
chmod with multiple file arguments. However; sed is perfectly
capable of storing up multiple lines in its hold buffer, and
essentially turning it into _one_ chmod command, (reinforcing my
contention that minimizing process creation is an important
consideration of the shell programmer) but I wanted to keep the
example code above simple.
P.P.P.S. Is it true that all Swedes speak/write as good or better
English than native speakers? :-) I have never met or known of a
Swede who couldn't converse in English quite respectably.
-James
J-P
On 17 Jan 1998 21:08:49 GMT, jrma...@rainey.blueneptune.com (James R.
Martin) wrote:
>P.P.P.S. Is it true that all Swedes speak/write as good or better
>English than native speakers? :-) I have never met or known of a
>Swede who couldn't converse in English quite respectably.
>
>-James
>