commit: baace72c616e0c9b5263f4ea327e2c941d0a6bfa
parent: 75615d58440ce29ed73b6dfc6d7aad358f12d830
author: z0noxz <chris@noxz.tech>
date: Tue, 7 Aug 2018 10:20:04 +0200
read from stdin if applicable
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/ip2cidr b/ip2cidr
@@ -106,11 +106,19 @@ do_ip2cidr() {
return 0
}
+# read from stdin if applicable
+x="$1"
+if ! [ -t 0 ]; then
+ while read -r line; do
+ x="$line"
+ done
+fi
+
# check if input already is a CIDR, and if not process it
-if [ "$1" -eq "$1" ] 2> /dev/null && [ "$1" -le 32 ] && [ "$1" -gt 0 ]; then
- printf '%d\n' "$1" && exit 0
+if [ "$x" -eq "$x" ] 2> /dev/null && [ "$x" -le 32 ] && [ "$x" -gt 0 ]; then
+ printf '%d\n' "$x" && exit 0
else
- do_ip2cidr "$1" && exit 0
+ do_ip2cidr "$x" && exit 0
fi