LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2007, 02:30 PM   #1
resolute155
LQ Newbie
 
Registered: Dec 2006
Posts: 9

Rep: Reputation: 0
Linux variables with cp command


Hello,

I have a .img file in multiple folders that I would like to copy to a new folder. For subject 301_A, for example, the file I want to copy is 301_A_mpflash.img. There are similar files in the same folder, such as r301_A_mpflash.img, that I don't want to copy so I need to be specific.

Below is a small part of the script that I wrote to accomplish this, however, I get an error with the $subject_mpflash.img portion. So in general, how can you use a variable in this kind of situation? Any help would be greatly appreciated.

Thanks,
David



for subject in 301_A 301_B 302_A
do

cp /data/$subject/Anatomy/$subject_mpflash.img /data/group/$subject/

done
 
Old 09-17-2007, 03:02 PM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
YOu may need to use bracketed syntax like this: ${var}
But, I think you are still going to have trouble because variable contsructed like this may vbe treated as arrays: $var_
If so, this may work: $'var'_rest.of.name
 
Old 09-17-2007, 03:11 PM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Or
Code:
cp /data/"$subject"/Anatomy/"$subject"_mpflash.img /data/group/"$subject"/
may work.
 
  


Reply



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
entering variables using 'read' command: how to blank text? adamrosspayne Linux - Newbie 1 07-04-2006 01:37 AM
Using Variables in a Command that uses a Directory (Shell Script) CrimsonSkyZS Linux - General 4 01-11-2006 03:18 PM
insmod command variables in a script fpb Linux - General 2 01-03-2006 07:29 PM
is there a command to view all variables? ginda Linux - Newbie 1 09-29-2005 03:16 PM
Getting o/p of command in variables kushalkoolwal Programming 8 09-25-2005 10:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:54 AM.

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
Open Source Consulting | Domain Registration