I'm writing a bash script to get the latest file from a directory for backup purposes. Here is the script:
#!/bin/sh
set -u
set -e
backup_dir=/media/backup
cd $backup_dir
tar_file= $(ls -Art | tail -n 1)
#ls -Art | tail -n 1
echo $tar_file
When I run the script it gets the right file but also returns a not found error and I don't know why:
./backup: 10: 20130403-120001.tar.gz: not found
I tested it with the line that's commented out, not putting it as a variable and that works without throwing an error so it should work.