我试图在我的debian7 bash中生成许多无效的ipv4地址和一些有效的地址。 我的计划是:
echo {0..3 , 00..03 , 000..003 , 300..303 , 254..257 , 0254..0257 , fail , 888}
echo -e "\n"!^.!^.!^.!^ >> ip.txt
但它只是回应
"{0..3 00..03 000..003 300..303 254..257 0254..0257 fail 888}" x4
每当我为每个花括号提供多个数字区域时。
echo {a..c , A..C} end up as
"{a..c A..C}"
where i want
"a b c A B C"
所以我很好奇,如果甚至可以使用>>只有一个大括号<<
__
我的下一个想法是像这样解决它:
echo -e "\n"{0..3}.{0..3}.{0..3}.{0..3} >> ip.txt
^0..3^00..03
but there is only replaces one piece
echo -e "\n"{00..03}.{0..3}.{0..3}.{0..3} >> ip.txt
有没有办法使用这个“^ x ^ y”工具一次性替换所有?
抱歉这个基本问题我刚刚进入bash并想在家里学习除了学校课程
感谢任何有关必要文献的帮助或提示
答案 0 :(得分:1)
我猜你想要这样的事情:
for a in {{0..3},{00..03},{000..003},{300..303},{254..257},{0254..0257},fail,888} ; do
for b in {{0..3},{00..03},{000..003},{300..303},{254..257},{0254..0257},fail,888} ; do
for c in {{0..3},{00..03},{000..003},{300..303},{254..257},{0254..0257},fail,888} ; do
for d in {{0..3},{00..03},{000..003},{300..303},{254..257},{0254..0257},fail,888} ; do
echo "$a"."$b"."$c"."$d"
done
done
done
done
脚本输出456976
想要的IP地址:
0.0.0.0
0.0.0.1
0.0.0.2
0.0.0.3
0.0.0.00
...
888.888.888.0255
888.888.888.0256
888.888.888.0257
888.888.888.fail
888.888.888.888
如果你想避免使用循环,你可以用.
这样连接每个部分:
echo -e {{1..3},{5..7}}.{{1..3},{5..7}}.{{1..3},{5..7}}.{{1..3},{5..7}}"\n"