Q:

variable showing in terminal instead of being appended into a file on Bash

I am doing an assignment which involves in appending a variable to a file.  but the output is going out in the Terminal instead of outputting in the file.  Can you help me please? 
This is the code

#! /bin/bash

cdate=$ date | awk '{print $2" "$3" "$4}'
IP_r=$ $cdate ifconfig ens33 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'

echo $IP_r >> /home/admin17/ip_address.log

and this is the output
24 Dec 23:52:25
192.168.180.131
admin17@SERVERAS:~$

basically i want the date and IP address in the file /home/admin17/ip_address.log
Thank you

A:

Try this: 
cdate="$(date | awk '{print $2" "$3" "$4}')"
IP_r="$(ifconfig ens33 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}')"

echo $cdate $IP_r >> "/home/admin17/ip_address.log"`

If you want the output on different lines then just use \n
echo -e $cdate\n$IP_r >> "/home/admin17/ip_address.log"

Output from ~/ip_address.log: 

 cat ~/ip_address.log
 25 Dec 01:08:54
 192.168.1.104

