dms_programmer
dms_programmer

Reputation: 99

Error copying files in Linux shell bash script

I'm try to copy files from a location (/home/ppaa/workspace/partial/medium) to another location (/home/ppaa/workspace/complete) using bash shell scripting in Linux.

This is my code:

#!/bin/bash -u

MY_BASE_FOLDER='/home/ppaa/workspace/'
MY_TARGET_FOLDER='/home/ppaa/workspace/complete/'
cp $MY_BASE_FOLDER'partial/medium/*.*' $MY_TARGET_FOLDER
return=$?
echo "return: $return"

The folders exists and the files are copied but the value of return variable is 1. Whats wrong?

Upvotes: 0

Views: 1736

Answers (1)

that other guy
that other guy

Reputation: 123700

The files are not copied. cp is most likely giving you an error like:

cp: cannot stat ‘/home/ppaa/workspace/partial/medium/*.*’: No such file or directory

This is because globs (like *.*) are not expanded in quotes. Instead, use:

cp "$MY_BASE_FOLDER/partial/medium"/*.* "$MY_TARGET_FOLDER"

Upvotes: 2

Related Questions