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

Daniel E Singer des at cs.duke.edu
Tue Mar 16 11:34:21 EST 2004


On Tue, 16 Mar 2004, Gantt Edmiston wrote:

 > Here is a brief extract from a 1200 line data file, named LIST,
 > of fully qualified pathnames to files:
 >
 > /usr/local/foo bar/file1
 > /usr/local/foo bar/file2
 > /usr/local/foo bar/
 > ...
 > Normally, in bash, I would do:
 >     for x in $(cat LIST)
 >       do
 >       chmod o-w $x
 >       done
 >
 > But the shell has issues with the white space and the whole thing fails.
 > ...

I'm more familiar with plain Bourne shell as opposed to bash, but the
idea will be the same.  Basically, you want to set the IFS (internal
field separator) to just newline for this sort of situation, something
like:

	_IFS="$IFS"
	# note: next line contains newline between single quotes
	IFS='
'
	# I usually throw this in too, to suppress filename expansions
	# on data read in (if I'm doing a while loop)
	set -f
	while read file; do
		chmod o-w "$file"
	  done < LIST
	IFS="$_IFS"
	set +f

and something similar with a for loop should work:

	_IFS="$IFS"
	IFS='
'
	set -f
	for file in `cat LIST`; do
		chmod o-w "$file"
	  done
	IFS="$_IFS"
	set +f

HTH

-Dan

-- 
Daniel E. Singer, System Administrator
Dept. of Computer Science, Duke University, Durham NC 27708 USA


More information about the ncsa-discussion mailing list