How-To question for the NC*SA brain trust...

Lance A. Brown brown9 at niehs.nih.gov
Tue Mar 16 18:29:45 EST 2004


On Tue, 2004-03-16 at 17:11, John Strickler wrote:
> Another simple approach is to use the shell's (bash or ksh) *read* command and put quotes around the variable
> 
> while read $x
> do
>      chmod o-w "$x"
> done < list
> 
> This performs one chmod per file, unlike the xargs-type solutions, but has the advantage of being very tidy

This breaks when there are spaces in the file names, as we have here. 
The read command will pull apart each input line at the space and return
the chunks.

You would want to play with IFS (in sh style shells) if you want this
syntax so the separator doesn't include spaces.

--[Lance]

> 
> -----Original Message-----
> From: "Lance A. Brown" <brown9 at niehs.nih.gov>
> Sent: Mar 16, 2004 4:47 PM
> To: NC*SA Discussion List <ncsa-discussion at ncsysadmin.org>
> Subject: Re: How-To question for the NC*SA brain trust...
> 
> What about something like:
> 
> cat $list | sed -e 's/^/"/' -e 's/$/"/' | xargs chmod o-w
> 
> This results in fewer chmod commands being executed.
> 
> I often use that sed statement while doing finds and whatnot in
> directory spaces in samba shares, etc.
> 
> --[Lance]
-- 
Lance A. Brown
SysAdmin Task
LMIT ITSS Contract for 
National Institute of Environmental Health Sciences
919.361.5444x420



More information about the ncsa-discussion mailing list