M
M
Monartoi2022-03-03 15:54:41
linux
Monartoi, 2022-03-03 15:54:41

Why doesn't the script show hostname?

Script, returns an empty string instead of hostname

#!/bin/sh
hm=$HOSTNAME
echo $hm

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Antony, 2022-03-03
@RiseOfDeath

Do you have such a variable in the environment at all?
To begin with, add to the script
printenv
. In general, to begin with, type hostname or cat /etc/hostname in the console, perhaps the script is doing everything right.

V
Victor Taran, 2022-03-05
@shambler81

Perhaps everything is simpler and he was trying to simply declare this variable
hm=$(hostname); echo $hm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question