LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-30-2004, 04:34 PM   #1
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Rep: Reputation: 15
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
 
Old 12-30-2004, 04:49 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
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
 
Old 12-31-2004, 07:27 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 02:03 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 10:00 AM
searching "TIC TAC TOE" bash script LV-chronos Linux - Newbie 5 05-29-2005 03:20 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 02:45 AM


All times are GMT -5. The time now is 12:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration