I am using the below code to extract the names of files in a folder and then performing an operation on those files.
for library in lib/*
do
echo ${library##*/}
cp -v ${library##*/} /opt/java/deploy/
done
}
The above yields an output of :
camel-amqp-2.16.0.jar
netty-all.jar
proton-j.jar
qpid-jms-client.jar
I then need to copy the jar files one by one in the application deployment folder.
Right now I have 4 jar files but in the future the # of files will increase.
The above works all fine. But the dilemma for me is that I have to make sure that qpid-jms-client.jar
& camel-amqp-2.16.0.jar
are the last to load.
Basically I need to sort the output so that the qpid & camel jar files are at the bottom of the list and are hence the last ones to be loaded.
Using sort
does not help here since sorting alphabetically wont be of much use.
Is there something else I can try out ?
答案 0 :(得分:0)
使用extglob
即可:
shopt -s extglob nullglob
for lib in !(@(qpid-jms-client|camel-amqp-*)).jar qpid-jms-client.jar camel-amqp-*.jar; do
echo "${lib##*/}"
cp -v "${lib##*/}" /opt/java/deploy/
done
工作原理:
!(@(qpid-jms-client|camel-amqp-*)).jar
匹配除*.jar
&之外的所有qpid-jms-client.jar
个文件camel-amqp-2.16.0.jar
个文件。