I'm trying to run a simple shell ( Centos 7 ) that print out the system HOSTNAME variable:
test.sh
#!/bin/ksh
echo "HOSTNAME:"$HOSTNAME
when executed from bash or ksh the shell does not work as expected
>ksh ./test.sh ----> HOSTNAME is unset
>./test.sh ----> HOSTNAME is unset
if i create a ~/.profile that declare and export HOSTNAME nothing change. if i crate a ~./kshrc that source ~./profile works only if i switch from bash to ksh and execute the script.
if i run from bash the following code it does work due to the interactive mode
ksh -xi ./test.sh
+ command . ./.profile
+ HOSTNAME=<MYNAME>
+ export HOSTNAME
+ export HOSTNAME
+ echo HOSTNAME:<MYNAME>
HOSTNAME:<MYNAME>
without interactive mode ~/.profile is not loaded
+ echo HOSTNAME:
HOSTNAME:
I need to have original HOSTNAME set even in ksh due to a bunch of scripts that use HOSTNAME variable
PS: i've tried printing PATH variable and it's working even when HOSTNAME does not
Could you please give me some advice?