mirror of
https://github.com/kastdeur/dotfiles.git
synced 2024-12-22 01:03:35 +01:00
[bin] added dotrev utility
This commit is contained in:
parent
0be4faaca0
commit
600f31775a
1 changed files with 23 additions and 0 deletions
23
bin/dotrev
Executable file
23
bin/dotrev
Executable file
|
@ -0,0 +1,23 @@
|
||||||
|
#!/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
|
Loading…
Reference in a new issue