D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] bash shell script question

 

On Fri, 2 Jan 2015, Martijn Grooten wrote:

On Fri, Jan 02, 2015 at 04:57:53PM +0000, Martijn Grooten wrote:
On Fri, Jan 02, 2015 at 04:47:41PM +0000, Paul Sutton wrote:
1.  Put the out put to hostname -I as a variable and display that OR
2   put the output as an environment variable e.g $HOSTNAME and
display that

Just not sure on HOW to do this

  hostname=`hostname -I`; echo "Hostname: $hostname"

Actually,

 echo "hostname:" `hostname -I`

is much better, and is a proper answer to 1.

Personally, I'd use:

  echo "My IP address is: `hostname -I`"

However... the hostname command might not be the best all-rounder, but some something like a personal computer it might be fine, but e.g.:

gordon @ watertower: hostname -I 192.168.1.2 192.168.254.1 81.31.100.110 81.31.100.109 81.31.100.106 192.168.247.1 81.31.100.105 2001:4d48:ad51:8901::1 2001:4d48:ad51:8902::1 2001:4d48:ad51:8900::1

Now which one do I pick...

Happy new year, everyone.

Gordon

--
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq