Hi All
I need to put a bunch of specific files in a directory (with loads of other files), into a tar archive. The best way I thought of doing this was putting the filenames into a file, reading them line by line in a for loop, and then adding them to a tar acrhive.
However the filenames have spaces:
/the/path/to/the/file/the file name with spaces
So when I do a for x in `cat /listoffiles` etc, it doesn't work because the shell sees the spaces as separators, and hence the bits of the name as separate files.
Anyone got a resolution to this? If I list the filename at the command line, enclosed by quotes, it's OK - but when I put $x in quotes in my for loop, it doesn't work.
jim's solution will not work. The problem is "for x in `cat listoffiles`" will spilt the contents of listoffiles on whitespace. So with the example given, x will be "the" then it will be "file". And so on. Placing $x in quotes isn't enough because it's too late...the filename was split before x got a value.
My solution would be:
#! /usr/bin/ksh
exec < listoffiles
while read x ; do
somecommand "$x"
done
Hi All,
I am using the same while syntax for reading my file but its not working for my code.
Below is the line in my file
" 123 rteyu 566"
when I use below code the spaces are shifted especially for 1st variable
while read line
do
x=`echo "$line"|cut -c 1-7`
y=`echo "$line"|cut -c 8-15`
echo "$x"
echo "$y"
done < file
x is showing value "123 ".
The intial spacing is being trucated.
Can any one help me on this!!!!!!