1
0
Fork 0
mirror of https://github.com/kastdeur/dotfiles.git synced 2024-12-22 09:13:33 +01:00
dotfiles/bin/dotrev

24 lines
478 B
Text
Raw Normal View History

2021-01-07 15:58:53 +01:00
#!/bin/bash
# dotrev
# Reverse the order of substrings within a dotted string.
# Example: deboone.nl -> nl.deboone
while [ -n "$1" ]; do
tmp="$1"
REVHOSTNAME=""
while [ -n "$tmp" ]; do
piece="${tmp##*.}."
tmp="${tmp%.*}"
REVHOSTNAME="${REVHOSTNAME}${piece}"
if ! case "$tmp" in *.*) ;; *) false;; esac; then
REVHOSTNAME="${REVHOSTNAME}${tmp}"
unset tmp
unset piece
break;
fi
done
echo $REVHOSTNAME
shift
done