I'm trying to get the filename of the newest file in a directory and store it in a variable. The files in the directory end with *.db.backup. When I try to run the command without storing the result in a variable it is correct, but when I try to store it in a variable for later use and echo the '.' are replaced by spaces. Any ideas as to what I am missing here?
ls -1t | grep "db.backup" | head -1
#Output:
2022-01-11-001712-gravity.db.backup
filename=$(ls -1t | grep "db.backup" | head -1)
echo $filename
#Output:
2022-01-11-001712-gravity db backup