bash从作为变量传递的文件中删除文件
我以前问过一次,但现在下面的bash从作为变量传递的文件中删除文件,bash,Bash,我以前问过一次,但现在下面的bash似乎删除并下载了输入文件中的所有文件。基本上,输入中的所有行(6)都是文件,并被读入$line变量。当我echo看到$line时,我可以看到那里的文件,它们确实被删除了,但它们也被下载了,我不需要它们,我也不知道它们为什么会被删除。谢谢:) strong文本 file1.txt file2.txt file3.txt file1.pdf file2.pdf file3.pdf bash # add filenames as variable and remo
bash
似乎删除并下载了输入文件中的所有文件。基本上,输入中的所有行(6)都是文件,并被读入$line
变量。当我echo
看到$line
时,我可以看到那里的文件,它们确实被删除了,但它们也被下载了,我不需要它们,我也不知道它们为什么会被删除。谢谢:)
strong文本
file1.txt
file2.txt
file3.txt
file1.pdf
file2.pdf
file3.pdf
bash
# add filenames as variable and remove files from list
while read line; do
echo $line (only there to verify that the files are in the variable)
wget --user=xxxxx --password=xxx --xxxx --method=DELETE \
xxx://www.example.com/xx/xxx/xxx/$line
done < /home/cmccabe/list
rm /home/cmccabe/list
#将文件名添加为变量并从列表中删除文件
读行时;做
echo$行(仅用于验证文件是否在变量中)
wget--user=xxxxx--password=xxx--xxxx--method=DELETE\
xxx://www.example.com/xx/xxx/xxx/美元线
完成
您可以使用-O/dev/null
选项,即:
wget --user=xxxxx --password=xxx --xxxx --method=DELETE \
xxx://www.example.com/xx/xxx/xxx/$line -O /dev/null
放弃wget的输出并避免保存输出文件。这是wget问题,而不是bash问题。您希望wget调用做什么?当您使用如下变量时:xxx://www.example.com/xx/xxx/xxx/$line,应将整个字符串或至少变量括在双引号中,如下所示:xxx://www.example.com/xx/xxx/xxx/$line”。当源文件包含类似“my cool file with spaces.txt”的内容时,它将防止您出现任何可能的语法错误。非常感谢:)。