Anonymous Anonymous - 2 years ago 155
Bash Question

Shell Script - Get name of dynamically generated file

I'm very new to shell script and therefore I don't now very much about it.
I have an application, which creates a java file with a half unknown name, and now I try to write a script, which needs this name.

The known name of the file is

/target/plugin-<dyn>.jar
, the
<dyn>
part is unknown and could be nearly anything (btw it is mostly a version number with variable text parts).

Now I want to save
plugin-<dyn>
(without the
.jar
) in a variable for later use. I looked very much in the internet, but I can't find a solution.

Answer Source

If you need get file name without extension .jar. You can refer my bash script below:

# for loop all files in target directory that matched plugin-*.jar
for f in target/plugin-*.jar
do 
    # print file name without extension .jar
    echo ${f%.*}
done