My dash script takes a parameter in the form of hostname:port, i.e.:
myhost:1234
Whereas port is optional, i.e.:
myhost
I need to read the host and port into separate variables. In the first case, I can do:
HOST=${1%%:*}
PORT=${1##*:}
But that does not work in second case, when port was omitted; echo ${1##*:} simply returns hostname, instead of an empty string.
In Bash, I could do:
IFS=: read A B <<< asdf:111
But that does not work in dash.
Can I split string on : in dash, without invoking external programs (awk, tr, etc.)?