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.txtnewFile-1.0.0.txtsample.txtMy script sc.sh:file_path=/home/user/handsOnvar=$file_path/file-1.2.0-SNAPSHOT.txtnewLocation=/new_pathcp $var $newLocationNow 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
Find a file matching with certain pattern and giving that file name as value to a variable in shell script?
linux;bash;shell script
Finally, got the solution after many trial and error methods:cd $file_path && fVar=$(find -type f -name 'file-[0-9].[0-9].[0-9]-SNAPSHOT.txt');echo $fvar # output is like ./file-1.2.0-SNAPSHOT.txtfT=${fVar:2} # removing first two characters'./'echo $fT # output is file-1.2.0-SNAPSHOT.txtThanks Rakesh  for  contributing your answer, it helped me..