【发布时间】:2019-12-24 03:27:18
【问题描述】:
我就是这样开始的。很简单的事情。
a="abc"
b="ABC"
if [ "$a" == "$b" ]; then
echo "Strings $a & $b match"
else
echo "Strings $a don't match $b"
fi
然后我尝试了这个。即使我还没有下载它,它总是说跳过。
input="file"
while IFS= read -r line; do
path="${line%/*}"
file="${line##*/}"
if [ $line = $file ]; then
echo "skipping ${file##*/}"
else
wget -nc -q --show-progress "${path}/${file}"
sleep 1
fi
done < "$input"
我也试过这个。我知道这是错误的,因为我没有任何东西可以让 y 匹配 x。我试图在 wget 中使用 y 作为变量来匹配我的文件 x 中的某些内容。
for x in $(cat file); do
for y in ???; do
if [ "$x" == "$y" ]; then
echo "${x##*/} & ${y##*/} match skipping download"
else
echo "${x##*/} don't match ${y##*/} downloading"
sleep 1
wget -q -nc --show-progress "$y"
fi
done
done
我真的只想运行一个基本循环,以便在下载时检查我的文件。如果已经存在则跳过文件,如果没有下载文件。
【问题讨论】:
-
为什么不只是
wget -N? -
我对此很陌生,正在寻找任何可能性。如果这可行并获得学习编码的经验,希望为我的 bash 添加更多内容。谢谢。
-
"$input"文件中有什么内容?请发布示例输入。您的脚本中发生了什么?你想达到什么目标?为什么不直接使用wget -N呢?[ $line = $file ]只是比较字符串,它不检查文件是否存在。你想用你的脚本做什么?
标签: bash loops if-statement