1834007 Members
2025 Online
110063 Solutions
New Discussion

Variable Question

 
Hunki
Super Advisor

Variable Question

Is this a correct variable inside a .profile for a user :

export HostName=`/usr/ucb/hostname`

OR whether it should be

HostName=`/usr/ucb/hostname`

thanks,
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: Variable Question

Hi:

Well, for HP-UX if you want to capture the server hostname and provide it to processes started after login, you would place this in the users '.profile':

# export HostName=`/usr/bin/hostname`

(or, using the preferred POSIX form)

# export HostName=$(/usr/bin/hostname)

Regards!

...JRF...
Sandman!
Honored Contributor

Re: Variable Question

/usr/ucb/hostname is for the Berkeley version of the hostname command. You should use either /bin/hostname or /usr/bin/hostname utils.
hpuxrox
Respected Contributor

Re: Variable Question

I use the export so the variable will be inherent to child shells. But that is totally up to you.
Sunny Jaisinghani
Trusted Contributor

Re: Variable Question

hi,

It is always better to export a variable if it is used very frequently and also if its value doesn't change very frequently.
also it should be user specific and hence it is appropriate to include this in the .profile file for a user.

Regards
Arturo Galbiati
Esteemed Contributor

Re: Variable Question

Hi Hunki,
if you want to have the full name of teh host:

export HstNam=$(hostname|nslookup|awk '/^Name:/ {print $2}')

bosth hostname and nslookup are in /usr/bin, but I think you don't need to sue teh fullpath, usially /usr/bin is included in default path.

HTH,
Art
Reshma Malusare
Trusted Contributor

Re: Variable Question

Hi Hunki,
We normally export such things which we used regularly. Hostname is common one.

option is :

# export HostName=$(/usr/bin/hostname)

Regards
Reshma