0

I am creating a logfile from kermit named the current date (which is in the format of DD MMM YYYY - which can not be changed AFAIK), and using the file name as today's date.

I then have a Bash script to read the file and I want to tail -n1 the file.

if I do

    filename=$(date +%d\ %b\ %Y) && echo $filename

I get

    23 Feb 2015

which is what I want and expect. However if I then do

    filename=$(date +%d\ %b\ %Y) && tail -n1 $filename

I get

    tail: cannot open `23' for reading: No such file or directory
    tail: cannot open `Feb' for reading: No such file or directory
    tail: cannot open `2015' for reading: No such file or directory

I am not sure what is causing this, probably down to the the way I have string formatted I guess since I get the same if I use tail or cat?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • It is better to ask a direct question like "What causes tail to give these errors and how do I solve this?" than to ask for me specifically to offer assistance (I'm not always online, nor do I know everything). – anyone Feb 24 '15 at 15:45

1 Answers1

1

Double-quote your variables. Double-quote your variables. Double-quote your variables.

filename=$(date +'%d %b %Y') && tail -n1 "$filename"
Chris Davies
  • 116,213
  • 16
  • 160
  • 287