I am finding a way to get the filename assigned to a variable in my shell script. But my file has naming format as file-1.2.0-SNAPSHOT.txt.
Here the numbers may change sometimes, now how can i assign this filename to a variable. Any regex can be used? or grep? or find? or file?
My directory consists of following files:
file-1.2.0-SNAPSHOT.txt newFile-1.0.0.txt sample.txt
My script sc.sh:
file_path="/home/user/handsOn" var=$file_path/file-1.2.0-SNAPSHOT.txt newLocation=/new_path cp $var $newLocation
Now the file version changes sometimes. My script should work for any version number.
How can I assign the matched filename to variable? Help me out. TIA