LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script using "cp" ...? (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-using-cp-272022/)

jimwelc 12-30-2004 03:34 PM

Bash script using "cp" ...?
 
Hello,

I am very new to the scripting world and I am trying to write a simple script to do copying of some files. I would like to use a wildcard to copy just the "*.abc" files from one directory to another. Below is the line I am using, but it does not seem to work within my script but if typed into the terminal it works fine. Can someone tell me what I'm doing wrong? Any help will be appreciated.

cp -i "/home/me/testdir/*.abc" "/etc/opt/testcopy/"

(both directories exist and again if this is typed on the cmd line it works fine but fails with the error message: "cp: cannot stat '/home/me/testdir/*.abc"



Best Regards,
-Jim

homey 12-30-2004 03:49 PM

Quote:

cp -i "/home/me/testdir/*.abc" "/etc/opt/testcopy/"
Hi,
the quotations probably aren't needed and the / after copy could be causing trouble.
cp -i /home/me/testdir/*.abc /etc/opt/testcopy

jschiwal 12-31-2004 06:27 AM

I don't agree with the second part of homey's advice. A slash at the end makes it explicit that the second argument is a directory. If there is only one file in testdir, and the target directory 'testcopy' doesn't exist, then a file testcopy would be created instead of causing an error. This is more important if it was part of a script.

Try this experiment: echo cp -i "/home/me/testdir/*.abc" "/home/me/testcopy/"
The * character is not expanded. If a file "\*.abc" existed in testdir, this file would be copied.


All times are GMT -5. The time now is 09:58 PM.