(EDIT in solution with sed)
I have a list of file names and directories, including tilde and wildcards. For instance:.
~/docs/file.*
~/my docs/*.txt
...
I read the lines and passed them to the command (e.g. rsync):
while read ROW
do
rsync $ROW /my/dest/
done < list.txt
The problem is handling with spaces in file names. If I put $ ROW in double quotes like this
rsync "$ROW" /my/dest/
Of course, bash does not get out of wildcards or tildes. But if I don't use quotation marks, space breaks the string.
One possible solution is to change the IFS (caution: the script is more complicated than the one I reported). Another solution (thanks for fixing Patrick Echterbruch) is the preliminary spaces. However, the following code does not work for me:
while read ROW
do
export NEWROW=$(echo $ROW | sed -e 's/ /\\ /g')
echo "Value: $NEWROW"
ls -1d $NEWROW
done < list.txt
, ls. "~/a b c/test.txt" , :
Value: ~/saver/a\ b\ c
, NEWROW ls , , , .
?
.