LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-22-2011, 11:15 PM   #1
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Post Script Syntax off -- Don't see it.


The script below copies the converted files to the directory I run the scrip out of. I have stared at this for awhile and outside of getting frustrated I can't see what is driving it. All the files should be worked out of the /tmp/ directory.

Any insight

Quote:
#! /bin/bash/
clear
figlet Year in Review
echo -e "\e[00;34m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \e[00m"
echo
echo -e "\e[00;31m What Year do you want to review ?\e[00;33m (IE : 2011, 2009) \e[00m"
read year
echo
echo -e "\e[107;34m Preparing Files .... Please wait.. \e[00m"

echo -e "\e[00;34m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \e[00m"

find /media/N-Space/Memories/"$year"/ -iname *jpg -exec cp {} /tmp/ \;
convert /tmp/*.jpg -resize 32X32 $(date +%N).jpg
rm /tmp/[A-Z*]*.jpg



for X in $(ls -l /tmp/[0-9*]*.jpg)
do

xcowsay --cow-size=small --image="$X" "I was taken in $year." 2>/dev/null

done
rm -vf /tmp/[0-9*]*.jpg


 
Old 12-22-2011, 11:39 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
I don't follow...

What is it doing/not doing? What is it that you want it to do/not do instead?

EDIT:
BTW
Code:
convert /tmp/*.jpg -resize 32X32 $(date +%N).jpg
By my reading of the convert man page, the convert command only takes one input file at a time. Therefore, you should not be giving it a wildcard that would match more than one file in /tmp.

EDIT2:
And, presuming that the convert man page is incomplete and multiple files can be specified, you would be converting all of the jpg files in /tmp and saving them all to the same, single filename in the current directory: $(date +%N).jpg

EDIT3:
If your goal is to convert them all one-at-a-time, then you need to build a loop around your convert command. That way, each iteration through the loop will give you one input file and "$(date +%N).jpg" will be re-evaluated for each conversion--giving a different output filename for each conversion.

EDIT4:
If the problem is that you don't like the conversion being saved in your current directory, then you need to change the output file in your convert command. For instance: "/tmp/$(date +%N).jpg"

At least, you seem to expect them in /tmp because of the subsequent:
Code:
for X in $(ls -l /tmp/[0-9*]*.jpg)
Keep in mind that you'll still need a loop for the conversion process as stated earlier.

Last edited by Dark_Helmet; 12-22-2011 at 11:53 PM.
 
Old 12-23-2011, 08:59 AM   #3
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 103Reputation: 103
Lightbulb

Thanks for the feedback. A secomd set of eyes and some experience is alwasy a plus !!

The variable I chose was nanosecond increment of time so I think thats why I get away withut the loop. I want to add another variable and decrement the value of X and enter into the --dream=$Y option which will have the picture thinking of another picture. I tried ((--$x)) but no luck. Any thoughts ?

Thanks again & Happy Holidays.

Quote:
#! /bin/bash
clear
figlet Year in Review
echo -e "\e[00;34m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \e[00m"
echo
echo -e "\e[00;31m What Year do you want to review ?\e[00;33m (IE : 2011, 2009) \e[00m"
read year
echo
echo -e "\e[107;34m Preparing Files .... Please wait.. \e[00m"

echo -e "\e[00;34m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \e[00m"

find /media/N-Space/Memories/"$year"/ -iname *jpg -exec cp {} /tmp/ \;
convert /tmp/*.jpg -resize 200X100 /tmp/$(date +%N).jpg
rm /tmp/[A-Za-z]*.{JPG,jpg}

for X in $(ls -l /tmp/[0-9*]*.jpg)
do
xcowsay --reading-speed=1000 --cow-size=medium --think --image="$X" "Fun times in $year" &>/dev/null
done
rm /tmp/[0-9*]*.jpg




 
Old 12-23-2011, 11:10 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Please, DO NOT USE QUOTE TAGS around code.

Use [code][/code] tags around your code and data, to preserve formatting and to improve readability. And in this case to keep the page from side scrolling.

You've been here for almost 3 years, so you should know this by now.


Quote:
The variable I chose was nanosecond increment of time so I think thats why I get away withut the loop.
No. Think about how the shell reads this command:
Code:
convert /tmp/*.jpg -resize 200X100 /tmp/$(date +%N).jpg
First, it breaks the line up into individual "words", then it does any parameter and command expansions for each word, and then finally the expanded command is executed. So the $(..) expansion is parsed only once, and convert is executed with only that single filename as its output argument.

You have to run a separate command for each input file in order to give them unique names.

convert does have quite a few options of its own for controlling input and output though, so you might want to research its features.
http://www.imagemagick.org/script/convert.php
http://www.imagemagick.org/Usage/

Not to mention that there's a good collection of scripts already available. Perhaps one of them will meet your needs.
http://www.fmwconcepts.com/imagemagick/index.php


Code:
for X in $(ls -l /tmp/[0-9*]*.jpg)
Sigh... How many times does this have to be repeated?

Do not parse ls for filenames!
http://mywiki.wooledge.org/ParsingLs

Do not read lines with for!
http://mywiki.wooledge.org/DontReadLinesWithFor


Besides, if you use "ls -l", you aren't getting just the filename, but all the metadata too. I don't think you want that.

To operate on a list of filenames, just use a globbing pattern directly. A for loop can handle globbing matches safely.

Code:
for X in /tmp/[0-9*]*.jpg ; do
( I'm not sure about that globbing pattern either, BTW, unless you expect some of the filenames to start with a literal "*" character. Did you perhaps want "/tmp/[0-9]*.jpg"? )


For more complex file matching use find of course, and if the action is too complex for -exec or xargs, switch to using a while+read loop. Again, don't use a for loop to read the output of a command.

Be sure to use the -print0 option when possible, also.

Last edited by David the H.; 12-23-2011 at 11:18 AM. Reason: nevermind, my mistake
 
1 members found this post helpful.
Old 12-23-2011, 12:10 PM   #5
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 103Reputation: 103
Wink

Thanks for the great input and reminders. I did some clean up below.

Also thanks for the links on the collection. I am more trying than anything else. So I am trying not to lean on toooo many people

Any thoughts on decrementing X to a file before it ?

I tried Variable=((--X)) ......................

Want to do something like this after I figure out how to decrement the x variable.
Code:
xcowsay --reading-speed=1000 --cow-size=medium --think --dream=$New_Decremented_Variable_of_$X --image="$X" "Fun times in $year" &>/dev/null 


Current Version.
Code:
#! /bin/bash
# floating-pic.sh 12/23/11

clear
figlet Year in Review
echo -e "\e[00;34m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \e[00m"
echo
echo -e "\e[00;31m What Year do you want to review ?\e[00;33m (IE : 2011, 2009) \e[00m"
read year
echo
echo -e "\e[107;34m Preparing Files .... Please wait.. \e[00m"

echo -e "\e[00;34m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \e[00m"

for j in $(find /media/N-Space/Memories/"$year"/ -iname *jpg -exec cp {} /tmp/ \;)
do
convert /tmp/"$j" -resize 200X100 /tmp/$(date +%N).jpg
done
rm /tmp/[A-Za-z]*.{JPG,jpg}

for X in /tmp/[0-9]*.jpg
do
xcowsay --reading-speed=1000 --cow-size=medium --think --image="$X" "Fun times in $year" &>/dev/null 
done
rm /tmp/[0-9*]*.jpg

Last edited by jv2112; 12-23-2011 at 12:15 PM.
 
Old 12-23-2011, 03:43 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by jv2112
Any thoughts on decrementing X to a file before it ?

I tried Variable=((--X)) ......................
The variable you are using, "X", contains text--not a number. You cannot subtract 1 from text to refer to the variable's previous value. It doesn't work that way.

If you want to refer to X's previous value, you must store a copy of it in another variable. Something like:
Code:
for X in /tmp/[0-9]*.jpg
do
  xcowsay --reading-speed=1000 --cow-size=medium --dream="$oldFilename" --think --image="$X" "Fun times in $year" &>/dev/null
  oldFilename=$X
done
Keep in mind, this will not work for the first picture displayed because there is no "previous filename" for X saved in oldFilename. You need to add some code to your script to check for that situation and adjust your command appropriately.

Last edited by Dark_Helmet; 12-23-2011 at 03:44 PM.
 
Old 12-23-2011, 06:16 PM   #7
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 103Reputation: 103
I was thinking since I renamed them as numeric names I could do it. The more I think about it it was quite silly of me....

Thanks for the wake up call.

If anybody else notices any other errors or opportunities I welcome the feedback. I noticed that when find searches on set of folders ( which has 841 jpg) it only copies and converts a dozen images bit it only happens to that folder.

Thanks again & Happy Holidays to all.
 
  


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
[SOLVED] need help with script syntax,etc linus72 Linux - General 3 09-10-2010 08:53 AM
[SOLVED] Script syntax error fw12 Programming 3 07-10-2010 02:31 AM
is there a '?:' syntax shell script? logicalfuzz Linux - General 3 01-29-2010 10:26 AM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 11:15 AM
Linux userid syntax requirements don't allow id to begin with a number bret Linux - Security 2 02-02-2006 05:38 PM


All times are GMT -5. The time now is 08:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration