Reputation: 3
I am new to Linux, and I am having an issue of not being able to fully execute these lines of code. I have researched for hours and have also spent plenty of time manipulating these myself and still cannot create something that looks how it should be. Thank you all ahead of time.
How it is supposed to look:
$. network.sh
Today is: Day, Month, Day (numerical), year
The hostname for localhost.localdomain is: 192.168.xxx.xxx
Here is how it currently looks.
. network.sh
Today is: Sunday, October 11, 2015
The hostname for localhost.localdomain
is: [kris@localhost Desktop]$
is
is on the next line. This completely disregards my last line of command and does not display it on the same line as "the hostname for localhost.localdomain".
Current file...
#!/bin/bash
# Script to print the current date
echo -n "Today is: "
d=$(date +%A," "%B" "%d," "%Y)
echo "$d"
# Show IP in color
echo -n "The hostname for " ; hostname ; echo -n "is:" ; echo -n ip addr list eth1 |grep "inet " |cut -d' ' -f6|cut -d/ -f1
Upvotes: 0
Views: 257
Reputation: 753525
You can use:
echo "The hostname for $(hostname) is: $(ip addr list eth1 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1)"
Or, I suggest:
ip=$(ip addr list eth1 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1)
echo "The hostname for $(hostname) is: $ip"
Upvotes: 1
Reputation: 392863
Just interpolate the sub processes outputs:
echo "The hostname for $(hostname) is: $(ip addr list eth1 |grep "inet " |cut -d' ' -f6|cut -d/ -f1)"
The nested "
are fine (the $(subshell) parsing takes precedence)
Upvotes: 2