MedicineMan
MedicineMan

Reputation: 15314

bash: find the name of a file and assign to a variable

In bash, I want to search a directory which contains a file that I'm expecting:

find . -name "myfile-*.war" 

assign the name of this file to a variable, and then rename the file to newfile.war.

Upvotes: 1

Views: 3806

Answers (2)

Barmar
Barmar

Reputation: 780673

You don't need to assign the file to a variable, just rename it with the -execdir option to find:

find . -name 'myfile-*.var' -execdir mv {} newfile.war \;

Upvotes: 1

Dan
Dan

Reputation: 11084

If you are sure the find command will return exactly 1 file you can use this:

name=$(find . -name "myfile-*.war" )

Upvotes: 3

Related Questions