1

I have cut out a piece of my Bash script that I cannot get to function as it should. I want to copy the content of the folder gmp-5.0.4 into gcc-4.6.3/gmp these packages have been unpacked earlier in the script:

GMP_PACKAGE=ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.4.tar.bz2
GCC_PACKAGE=http://mirrors.kernel.org/gnu/gcc/gcc-4.6.3/gcc-core-4.6.3.tar.bz2

copy_math_libraries()
{
        LOCATION="$1"

        mkdir "$LOCATION/gmp"
        cp -v -r "$PACKAGES/`basename $GMP_PACKAGE .tar.bz2`/*" "$LOCATION/gmp"
}

copy_math_libraries "$PACKAGES/`basename $GCC_PACKAGE .tar.bz2 | sed s/core-//`"

When running the script with set -x I get the following output:

++ cp -v -r '/home/klaus/toolchain/packages/gmp-5.0.4/*' /home/klaus/toolchain/packages/gcc-4.6.3/gmp
cp: cannot stat `/home/klaus/toolchain/packages/gmp-5.0.4/*': No such file or directory

If I open another shell and run the exact same command manually everything works as it should:

cp -v -r /home/klaus/toolchain/packages/gmp-5.0.4/* /home/klaus/toolchain/packages/gcc-4.6.3/gmp

Any suggestions are welcome.

2
  • Are you 100% sure the script actually unpacked the archives by the time copy_math_libraries gets called? Commented Mar 3, 2012 at 22:44
  • 1
    You don't run »the exact same command«. Do you see the quotation marks from set -x output in your command? Me neither. Commented Mar 3, 2012 at 22:48

2 Answers 2

2

Your * is not getting expanded.

Try this:

cp -v -r "$PACKAGES/`basename $GMP_PACKAGE .tar.bz2`/"* "$LOCATION/gmp"
Sign up to request clarification or add additional context in comments.

Comments

0

"…" prevent shell expansion (globbing). This should fix it:

cp -v -r "$PACKAGES/`basename $GMP_PACKAGE .tar.bz2`/"* "$LOCATION/gmp"

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.