ambiguous result with "info hostname "

MaheshD: The issue is as below :

My machine : pc-vj.sj.com

Bash command : "hostname" returns - pc-vj.sj.com and ip-address is 10.0.0.225

But

Tclsh8.4 command : "info hostname" returns - localhost.localdomain and ip-address is 127.0.0.1

Expected is the same behavior as the bash euqivalent "hostname".

Why is this ambiguity ? Is it not reliable to use "info hostname" ? If yes (not reliable), what is the equivalent command (other than bash hostname) ?

Lars H: How to find my own ip address is probably relevant reading. But if you know you'll always want exactly what the shell hostname command returns, then you can of course do exec hostname. Also, TclX has a host_info command.


MaheshD - 2010-04-08 06:04:33

The problem is not with fetching the ip-address. I have a function, which does sufficiently well to return the correct ip-address. Problem is with the hostname.


  1. Bug reports are best reported at http://tcl.sf.net/
  2. What OS and hardware are you using? What specific version of Tcl 8.4? (Run "info patchlevel" to find out).
  3. When I am on machine "myster" and I run info hostname in Tcl 8.6, I get back "myster". Notice that I don't get back an ip-address. So it is surprising to me that you get back an ip-address.

MaheshD - 2010-04-08 08:01:40

Sorry, for introducing the confusion. "info hostname" did not return any ip-address. The return value of the command "info hostname" was piped to another command to get the ip-address.

I have added the ip-address here just to emphasize the dependency on hostname to get the ip-address.

I will once again place my question more clearly :

machine name : pc-vj.sj.com

Bash command : hostname - It returns : pc-vj.sj.com , this is input to my GetIp () function which returns : 10.0.0.225

But

Tclsh8.4 command : info hostname - It returns : localhost.localdomain , this is input to my GetIp () function which returns : 127.0.0.1

The requirement from Tclsh command is the result same as that from the Bash equivalent hostname

  • Why is this ambiguity ?
  • Is it not reliable to use "info hostname" ?
  • If yes (not reliable), what is the equivalent command (other than bash hostname) ?

Martyn Smith - 2010-04-08 16:00 Tcl 8.4.12 RHEL 5 gives the real name of the machine not localhost. Could this be something in your /etc/hosts file ?


MaheshD - 2010-04-09 00:19:56

cat /etc/hosts shows :

127.0.0.1 localhost.localdomain localhost pc-vj.sj.com

10.0.0.225 pc-vj.sj.com

Probably this is the problem, if you look the syntax of /etc/hosts file :

         <IP_address> <myhost.example.org> <aliases>

The line one says :

127.0.0.1 localhost.localdomain localhost pc-vj.sj.com

It has the real name of the machine pc-vj.sj.com aliased to 127.0.0.1

I will change the settings, try it and then update this page.


MaheshD - 2010-04-09 00:31:06

Yes, the problem was due to the alias as mentioned in the previous comment.

Removing it resolves the issue.

But still, we need to ponder how Bash resolves it and why TCL fails to do so.