I have a list of files:
XX_1
XX_2
XX_3
whose numbers keep incrementing every single time I run the program. I want to find the latest file using a linux command. I tried:
find . -maxdepth 1 -name "*XX_*" -print
but this gives me all the files with XX_. I just want XX_3 and need to save the output that I get using this command to a variable so that I can copy the file. How do I do that? I tried:
var=$(ssh pi@192.168.0.101 ls -1 FlightLog* | sort -t_ -k2 -nr | head -1)
ssh pi@192.168.0.101 sftp "$var"
And I got the following error:
/Users/ykathur2/bin/GetFile.sh: line 3: var: command not found
ssh: Could not resolve hostname flightlog_88.dat: Name or service not known
Couldn't read packet: Connection reset by peer
Please help!