我正在尝试这样的一行:
for i in {1..600}; do wget http://example.com/search/link $i % 5; done;
我想要获得的输出是:
wget http://example.com/search/link0
wget http://example.com/search/link1
wget http://example.com/search/link2
wget http://example.com/search/link3
wget http://example.com/search/link4
wget http://example.com/search/link0
但是我实际上得到的只是:
wget http://example.com/search/link
bash
只返回余数,不是数学模的结果。这意味着,尽管数学上-12 mod 10
是8
,bash会将其计算为-2
。您可以使用简单的echo $((-12 % 10))
(-2
)测试它,并将其与python3 python3 -c "print(-12 % 10)"
(8
)比较。