How-To question for the NC*SA brain trust...
Lance A. Brown
brown9 at niehs.nih.gov
Tue Mar 16 21:38:00 EST 2004
You are most correct. I must be dredging up behaviour from some old
weird unix box or something...
I've been way wrong before. :-)
--[Lance]
On Tue, 2004-03-16 at 18:45, John Strickler wrote:
> I just tried with HP-UX v11 sh (Posix, not Bourne), and it also works great.
>
> To wit, I created the following file:
>
> -----------listfile---------------
> apple pie
> cherry tart
> apple brown betty
> --------------------------------
> then executed
> while read x
> do
> touch "$x"
> done < listfile
>
> this created the 3 files "apple pie", "cherry tart", and "apple brown betty", complete with spaces
>
> then I executed
>
> while read x
> do
> chmod 777 "$x"
> done < listfile
>
> and it changed the 3 files. It does not break when there are spaces in the file names.
>
> -----Original Message-----
> From: "Lance A. Brown" <brown9 at niehs.nih.gov>
> Sent: Mar 16, 2004 6:29 PM
> To: John Strickler <jstrick at mindspring.com>,
> NC*SA Discussion List <ncsa-discussion at ncsysadmin.org>
> Subject: Re: How-To question for the NC*SA brain trust...
>
> 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