How do I strip domain from hostname in pure Bash?
Example:
hostname = myserver.site.mydomain.com
output=${hostname#*.*}
will give
site.mydomain.com
while
hostname = myserver.site.mydomain.com
output=${hostname%*.*}
will give
myserver.site.mydomain
I want only "myserver"
Any ideas?
I wish to use pure Bash, not sed, awk, cut, etc.
What about:
hostname=myserver.site.mydomain.com
output=${hostname%%.*}
%% should remove longest match from tail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With