LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   HOSTNAME = hostname -> HOSTNAME: command not found ? (https://www.linuxquestions.org/questions/linux-software-2/hostname-%3D-hostname-hostname-command-not-found-4175474738/)

thomas2004ch 08-26-2013 04:38 AM

HOSTNAME = hostname -> HOSTNAME: command not found ?
 
My script looks as follow:

Code:

#!/bin/sh

echo hello world

HOSTNAME = hostname

echo $HOSTNAME

As I run it I got error as follow:
Code:

./test.sh: line 5: HOSTNAME: command not found
What could be the problem?

thomas2004ch 08-26-2013 04:57 AM

The problem is solved. I have to take out the space as follow:

Code:

#!/bin/sh

echo hello world

HOSTNAME=hostname

echo $HOSTNAME


SAbhi 08-26-2013 08:25 PM

Quote:

HOSTNAME=hostname

echo $HOSTNAME

so why this much hasle... ?

when you can do it like this, in one single line:

Code:

echo $HOSTNAME  #this will give the same output as $HOSTNAME variable is already been setup for hostname command.


All times are GMT -5. The time now is 06:16 AM.