Unable to assign command output to a variable

Posted by Harish Maralihalli on Ask Ubuntu See other posts from Ask Ubuntu or by Harish Maralihalli
Published on 2014-08-25T12:51:42Z Indexed on 2014/08/25 16:28 UTC
Read the original article Hit count: 1562

Filed under:

I am trying to assign the latest file name obtained from the below ls command but getting some error, it would be very nice if someone can answer how can I fix this!

fn=`ls -lrt pur_bom_interface_daily*.log | cut -c59-102 | tail -1`

or

fn=$(ls -lrt pur_bom_interface_daily*.log | cut -c59-102 | tail -1)

Error got:

ls: 0653-341 The file pur_bom_interface_daily*.log does not exist

Note: pur_bom_interface_daily*.log I am using * since there are multiple files starting their name with pur_bom_interface_daily and concatanated with the date on which they have got created.

© Ask Ubuntu or respective owner

Related posts about command-line