NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/53458: usr.sbin/ypserv/ypinit: error while checking hostname



    Date:        Fri, 20 Jul 2018 12:53:41 +0200
    From:        =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_Fauberteau?= <triaxx%NetBSD.org@localhost>
    Message-ID:  <3a0d2be66f8647ce8f31645ae18e72b9%NetBSD.org@localhost>

  | I don't really understand why the following script:
  | #!/bin/sh
  | HOSTNAME=foo
  | echo ${HOSTNAME}
  |
  | produces the following output:
  | defiler.triaxx.org

You are running into a feature of the NetBSD shell, ${HOSTNAME} is a built
in variable, that always expands to (effectively the same as) $(/bin/hostname)
(It doesn't matter what is assigned to it, that is ignored ... though I guess 
there is some argument to change that).

This is documented in sh(1) ...

     HOSTNAME   Set to the current hostname of the system, as returned by
                gethostname(3).  This is obtained each time HOSTNAME is
                expanded, so changes to the system's name are reflected
                without further action.  If unset, it returns nothing.
                Setting it does nothing except reverse the effect of an
                earlier unset.

It is intended (mostly) for use in PS1 (and similar places), often as 
${HOSTNAME%%.*}

kre



Home | Main Index | Thread Index | Old Index