Skip to content

Instantly share code, notes, and snippets.

@kylemanna
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylemanna/fd3fd5342932e37b71d9 to your computer and use it in GitHub Desktop.
Save kylemanna/fd3fd5342932e37b71d9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# https://www.debuggex.com/r/Hutq6OGOTwM8Qevp
#
#!/bin/sh
a() {
tmp=${1##*://}
proto=${1//:*/}
cn=${tmp%:*}
port=${1##*:}
port=${port-1194}
proto=${proto-udp}
}
b() {
a=$(echo "$@" | sed -re 's#((udp|tcp)://)?([0-9a-zA-Z\.]+)(:([0-9]+))?#proto=\2\ncn=\3\nport=\5\n#')
echo ret=$?
eval $a
#export proto cn port
}
c() {
if [[ "$@" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.]+)(:([0-9]+))?$ ]]; then
proto=${BASH_REMATCH[2]};
cn=${BASH_REMATCH[3]};
port=${BASH_REMATCH[5]};
else
echo "Did not match"
fi
}
#b $@
c $@
echo "proto: $proto"
echo "cn: $cn"
echo "port: $port"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment