简单的bash脚本来读取其内容的双引号一个文件 [英] Simple bash script to read from one file having double quotes in content
问题描述
好吧,我真的生气了:(
我有一个名为test.txt文件。在这里,它是:
的/ var / lib中/的backup.log
/var/lib/backup2.log
双引号都包含在每一个开头和目录的最终文件中,我无法将其删除。
我试图写一个脚本中的test.txt删除文件。
像这样的:
为德尔`猫test.txt`;做
RM -f $德尔
DONE
但它不按预期:(
它给这个错误:
RM:无法访问/var/lib/backup.log:没有这样的文件或目录
RM:无法访问/var/lib/backup.log2:没有这样的文件或目录
这将只是删除从一开始就引号字符和读条目,这比一味地清除所有引号字符(因为他们可以在出现更好的结束文件名,当然)。
和,对于您的初始code,请务必使用引号,直到你真正知道什么时候,什么时候不。
同时读取-r;做
FNAME = $ {回复#\\}
FNAME = $ {FNAME%\\}
回声RM -f$ FNAME
完成< myfiles.txt
Well i am really pissed off :( I have a file called test.txt. and here it is:
"/var/lib/backup.log"
"/var/lib/backup2.log"
double quotes are included in the file each at beginning and end of the directory and i can not remove them.
i am trying to write a script to remove files in test.txt. like this:
for del in `cat test.txt` ; do
rm -f $del
done
but it does not work as expected :(
it gives this error:
rm: cannot access "/var/lib/backup.log": No such file or directory
rm: cannot access "/var/lib/backup.log2": No such file or directory
This will just remove the quote character from the beginning and the end of the read entry, which is better than blindly removing all quote characters (since they can appear in filenames, of course).
And, regarding your initial code, PLEASE ALWAYS USE QUOTES until you really know when and when not.
while read -r; do
fname=${REPLY#\"}
fname=${fname%\"}
echo rm -f "$fname"
done < myfiles.txt
这篇关于简单的bash脚本来读取其内容的双引号一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!