1
0
Fork 0
mirror of https://github.com/kastdeur/dotfiles.git synced 2024-11-17 17:03:32 +01:00
dotfiles/bin/dotrev

23 lines
478 B
Bash
Executable file

#!/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