1

I have a file with SNAPSHOT in the name and I want to copy the file over to a new destination. I am not working within that directory, so I'll be using direct paths. I'm not great with bash commands so this is giving me some trouble. I feel though this should be very trivial.

This will be put into a script that will be copy hundreds of JAR files with the SNAPSHOT string attached to the file name. Here is something I have been working with but has been giving me trouble if my current working directory is not in the tree level of those jars.

cp "${SRC_PATH}"/grid-start/target/grid-start-* "${INSTALLER_PATH}"/boot/$(ls "${SRC_PATH}"/grid-start/target/*SNAP* | sed "s/-SNAPSHOT//")

Scenario:

File: /home/build/src/trunk/grid-start/target/grid-start-1.6-SNAPSHOT.jar

Dest: /home/build/installer/boot/grid-start-1.6.jar

Thanks!

1 Answer 1

1

I wrote this bash script for you. It should serve its purpose.

#!/bin/bash
#
# copier.sh

for f in $(find /home/build/ -name '*SNAPSHOT*');
do
    filename=${f##*/};
    filename=${filename/-SNAPSHOT};
    cp $f ./installer/$filename;
done

# EOF

Usage: run copier.sh from /home/build/ and it will copy(and remove -SNAPSHOT) to the /home/build/installer/ directory

It is kind of ugly, but it does what it should do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.