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, 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"

Another way, which works well to get rid of line breaks in bash scripts
in general, is

  echo "hostname:"| tr "\n" " "; hostname -I

Here 'tr' replaces all instances of "\n" (i.e. a line break) by spaces.

Martijn.

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