Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to supply either '-name' or '-sname' when starting an Erlang VM depending on whether the given string is a fully qualified name (FQDN) or not. What would be the quickest and environment-independent way of validating that? I am more interested in using some bash command (like 'getent' or 'nslookup' or others) rather than a regex expression. Best if it works in Ubuntu, FreeBSD and Solaris without changes and can be used in bash's 'if' easily.

share|improve this question
Pretty much any string can be a valid fqdn provided it has a dot in it or at the end, so a lookup is the only way to be certain. – Paul May 6 '14 at 14:04
You mean nslookup? That's what I mean. I want to make a lookup to be certain. I am just not sure if 'nslookup' is the way to go or maybe 'host' instead or something else? – Amiramix May 6 '14 at 14:06
it seems like it might be a better idea to target a python or perl method instead of shelling a utility. shells change all the time, but a system with python3 will always run the same method correctly, regardless of what platform its installed on, and how that platform is configured. – Frank Thomas May 6 '14 at 15:00
I just need to use it in an existing bash script when starting an Erlang node. Adding dependency on Python or Perl would be an overkill in my opinion. – Amiramix May 6 '14 at 16:45
up vote 1 down vote accepted

Host seems to work:

jalderman@mba:/tmp$ cat

for h in "bert" "ernie" ""
    host $h 2>&1 > /dev/null
    if [ $? -eq 0 ]
        echo "$h is a FQDN"
        echo "$h is not a FQDN"

jalderman@mba:/tmp$ ./ 
bert is not a FQDN
ernie is not a FQDN is a FQDN
share|improve this answer
Looks like host could be replaced with nslookup and the script would work pretty much the same. Thanks. – Amiramix May 7 '14 at 10:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.