cp not dealing with variable properly? please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp not dealing with variable properly? please help
# 1  
Old 03-19-2011
cp not dealing with variable properly? please help

I am having trouble with a script that is supposed to :

a)take all the jpg pictures in a given directory/parameter and create thumbnails of it in a directory on the desktop.

e.g
from /here/are/the/files.jpg to ~/Desktop/parser-the/files.png

this is my script: all the individual parts work but it falls apart when i put them together Smilie any help would be appreciated Smilie

Code:
  for picturesource in $(ls ${1}/*.[jJ][pP][gG])
                do
                        echo this is the picturesource $picturesource;
                        destination=~/Desktop/parser-"${picturesource}";
                        echo this is the destination $destination;
                        /bin/cp -Rf ${picturesource} ${destination}  && echo cp done ;
                        basenames=`basename ${destination}`;
                        echo this is basename $basenames;
                        echo eval="convert -thumbnail 137 $picturesource ${destination}.png" && echo eval and it goes here $destination;
                        ls ~/Desktop/parser* && echo now listing files in the folder
                        sleep 1
                done

Heres the output:

Code:
this is the picturesource test/hdgef.jpg
this is the destination /home/arbutt1/Desktop/parser-test/hdgef.jpg
/bin/cp: cannot create regular file `/home/arbutt1/Desktop/parser-test/hdgef.jpg': No such file or directory
this is basename hdgef.jpg
eval=convert -thumbnail 137 test/hdgef.jpg /home/arbutt1/Desktop/parser-test/hdgef.jpg.png
eval and it goes here /home/arbutt1/Desktop/parser-test/hdgef.jpg
/home/arbutt1/Desktop/parser-
now listing files in the folder

any help would be extremely appreciated Smilie

Last edited by orochinagi; 03-19-2011 at 05:22 PM..
# 2  
Old 03-19-2011
The cp fails simply because the target directory doesn't exist & cp won't create it, you'll have to mkdir it first. basename fails because you have a typo in the variable ($desitination instead of $destination)
This User Gave Thanks to pludi For This Post:
# 3  
Old 03-19-2011
Quote:
Originally Posted by pludi
The cp fails simply because the target directory doesn't exist & cp won't create it, you'll have to mkdir it first. basename fails because you have a typo in the variable ($desitination instead of $destination)
thank you so much for that advice! i cant believe how typos can manage to go unnoticed!

so i totally see your point,the destination directory doesn't exist. but what if the variable contains information about the directory itself. is the best plan of action to cut up the variable so we can extract the directory information e.g diff command? , then --> mkdir -p those directories before cp-ing the files?

Last edited by orochinagi; 03-19-2011 at 05:55 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Dealing with XML comments

I'm writing my own simple XML parser as an experiment. It's a lot more complicated than it's supposed to be. Things supposedly forbidden in XML comments happen all the time in the wild. You're never, ever supposed to find -- inside <!-- xml comments --> but in practice, you don't just find... (2 Replies)
Discussion started by: Corona688
2 Replies

2. Shell Programming and Scripting

Dealing with edge-list

I have an edge-list with nodes, edge.txt A B B J J H C A G H G A A C K G I have another file which tells me which of these nodes are important, input.txt G C A (3 Replies)
Discussion started by: Sanchari
3 Replies

3. UNIX for Dummies Questions & Answers

Dealing with sum

I have file input 1/1/2013 1AS030A 0 1083 CHINA 1/1/2013 1AS030B 0 675 KOREA 1/1/2013 1AS035A 162 662 CHINA 1/1/2013 1AS035B 51 799 INDIA 1/1/2013 1AS035C 0 731 CHINA 1/2/2013 1AS073A 10 1375 KOREA... (5 Replies)
Discussion started by: radius
5 Replies

4. Shell Programming and Scripting

variable option not properly recognized

I'm creating a junk script which utilizes either -l or -p to list files or remove files, respectively, in the junk directory. When I run this code, inputting '-p' is unrecognized through the whole if/else block and falls to the last else (echo do nothing). In addition, I switched tests and tested... (2 Replies)
Discussion started by: haishuva
2 Replies

5. Programming

Need help with Card Dealing Program

I'm currently making a card dealing program, it is suppose to display a list of cards like this: "Ace of Heart, is red" "Two of Heart, is red" . . "Ace of Spade, is black" and so on for all suits and numbers. here is my current code: #include <stdio.h> #include <stdlib.h> #include... (3 Replies)
Discussion started by: Izzy123
3 Replies

6. Shell Programming and Scripting

Dealing with files with spaces in the name

Hello, I'm a computer science major and I'm having problems dealing with file names with spaces in them. Particularly I'm saving a file name in a variable and then using the variable in a compare function i.e. a='te xt.txt' b='file2.txt' cmp $a $b If anyone could help me with this particular... (10 Replies)
Discussion started by: jakethegreycat
10 Replies

7. Shell Programming and Scripting

AWK: pattern not properly stored in variable?

Hey there, I have a table of contents file of the form 1 Title1 1.1 Subtitle1 1.1.1 Subsubtitle1 1.1.2 Subsubtitle2 ... and want to count the number of dots in the first field to find out the level of the section. I use the gsub function for the job, which works if I pass the pattern... (2 Replies)
Discussion started by: herrsimon
2 Replies

8. UNIX and Linux Applications

webinject - dealing with popups

Hello We have a webapp that launches a link in a popup. We need to use webinject to check the content of that popup but have been so far unsuccessful. We use webinject as a nagios plugin. Does anyone have any experience of using/configuring webinject and know if this is possible or not? ... (1 Reply)
Discussion started by: skewbie
1 Replies

9. Shell Programming and Scripting

Dealing with log files

Hi , My requirement is that i need to search for a number of strings in a log file and print them with line numbers.The search should be date wise. The sample log file is : Jan 17 02:45:34 srim6165 MQSIv500: (UKBRKR1P_B.LZ_ BENCHMARKS)BIP2648E: Message backed out to a queue; node... (6 Replies)
Discussion started by: charudpss
6 Replies

10. Shell Programming and Scripting

Help in dealing with arra

I am readinga file lin by line and based craeting a arry of unique elemenst from the second column of the line. However when i coem out of the while loop my array becomes empty , can eny one tell me what I would be doing wrong #!/bin/bash logfile="./mylog.dat" begin=100 end="$(( $begin +... (5 Replies)
Discussion started by: jojan
5 Replies
Login or Register to Ask a Question