Greetings,
I'm writing a simple bash script that needs to parse the contents of a file into an array. Entries in the file are "newline" delimited -- so the file would look something like this:
path/to/file
path/to/other/file
I'd like to parse in the contents and iterate over them. My code currently looks like:
CONTENT=`cat /path/to/text/file.txt`
for PATH in $CONTENT
do
echo $PATH
chmod -R 440 $PATH
fi
This code works great with a file with UNIX line-endings. With a windows formatted text file, however, it chokes miserably. The "echo $PATH" statement produces the correct path, but the chmod fails saying that the file doesn't exist. My knack is that the Windows line-endings aren't getting trimmed, so its trying to chmod a file-path that includes a new line character.
I need to make this thing work regardless of whether the target file was created with Unix or Windows newlines -- but given I am somewhat new to shell scripting I'm not all that sure how to do it.
I appreciate your help!