I want to send two variables as input to another command in shell script. I have tried many methods to send the two variables but I am getting unexpected problems with echo command.
#!/bin/sh echo $DATE_NOW1 Feb 17 2016 echo $HOURS1 13:06:47 echo "$DATE_NOW1 $HOURS1" output : 13:06:4716
the above string gives unexpected truncated output.i am getting the Variables after reading from a file.(ex : HOURS1=cat time_now |cut -d '.' -f 1
)
I have tried other methods like foo=”$date_now $hours” and foo “${date_now}${hours}” but still no use.
Can anyone point me where am I getting it wrong ?
Advertisement
Answer
Your variable DATE_NOW1 is terminated by a r character. As echo
always finishes the display by a n, echo $DATE_NOW1
works well (actually displays Feb 17 2016rn
). But when you concatenate, echo
displays this string :
Feb 17 2016r13:06:47rn
Try to remove the tailing r, or add a n at the end of DATE_NOW1