I am working in Linux bash.
I have a directory where I have files like this:
- xpto-10.20.30.tar.xz
- xpto-10.20.30.tar.xz
- xpto-20.20.30.tar.xz
- xpto-30.20.30.tar.xz
- xpto-10.20.30.tar.xz
- xpto-40.20.30.tar.xz
- xpto-40.20.9.tar.xz
I want to get the latest file version name, which should be xpto-40.20.30.tar.xz.
I am using this script:
#!/bin/bash
set_latest () {
eval "latest=\${$#}"
}
set_latest xpto-*.tar.xz
echo "The highest-numbered file is $latest"
But the result I am getting its xpto-40.20.9.tar.xz
I guess this is because of the number of characters. How can I get the latest file version name (considering this case)? Is there a way as well to get only version "40.30.30"?