<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://www.linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Sat May 18, 2013 1:22 pm by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Sat May 18, 2013 1:22 pm</pubDate>
  <lastBuildDate>Sat May 18, 2013 1:22 pm</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://www.linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>Re: Bash script only works once</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=26559#26559</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5312'&gt;TheDoctor&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Jul 03, 2006 1:29 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      &lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;nelz wrote:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;quote&quot;&gt;Not if there are no .jpg files in the current directory.&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
Which is what I think the problem is. And so I vote for nelz's amendment (find etc).</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=26559#26559</comments>
                                        <author>TheDoctor</author>
                                        <pubDate>Mon Jul 03, 2006 1:29 am</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=26559#26559</guid>
                                      </item>
                                      <item>
                                        <title>Re: Bash script only works once</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=26557#26557</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5'&gt;nelz&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Jul 03, 2006 12:58 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Not if there are no .jpg files in the current directory.</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=26557#26557</comments>
                                        <author>nelz</author>
                                        <pubDate>Mon Jul 03, 2006 12:58 am</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=26557#26557</guid>
                                      </item>
                                      <item>
                                        <title>Re: Bash script only works once</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=26546#26546</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=167'&gt;nordle&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Sun Jul 02, 2006 10:01 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      If you know the files are always going to be jpg, then&lt;br /&gt;
for file in *.jpg; do&lt;br /&gt;
should be ok too.</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=26546#26546</comments>
                                        <author>nordle</author>
                                        <pubDate>Sun Jul 02, 2006 10:01 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=26546#26546</guid>
                                      </item>
                                      <item>
                                        <title>Re: Bash script only works once</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=26536#26536</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5'&gt;nelz&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Sun Jul 02, 2006 9:39 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      It is fussy about the semi-colon, but only if the two commands (for and do) are on the same line.&lt;br /&gt;
&lt;br /&gt;
Replace&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;echo &amp;quot;What is the working directory? &amp;#40;include the final backslash&amp;#41;&amp;quot; &lt;br /&gt;
read workdir &lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
with&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;workdir=$&amp;#40;basename $&amp;#40;pwd&amp;#41;&amp;#41;&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
It saves you screwing things up with a typo.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;for file in *&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
will cause problems if you have no files, or some directories. A safer approach is&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;find -type f | while read file do...&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
Or you could install KPhotoAlbum and assign multiple attributes to every file, individually or in groups &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=26536#26536</comments>
                                        <author>nelz</author>
                                        <pubDate>Sun Jul 02, 2006 9:39 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=26536#26536</guid>
                                      </item>
                                      <item>
                                        <title>Re: Bash script only works once</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=26531#26531</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=167'&gt;nordle&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Sun Jul 02, 2006 9:27 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      oh ok, I thought it was fussy about having the semi colon, guess not.&lt;br /&gt;
&lt;br /&gt;
But yeah, a dir test would help:&lt;br /&gt;
&lt;br /&gt;
if [ ! -d $workdir ]; then&lt;br /&gt;
  echo &quot;$workdir does not exist&quot;&lt;br /&gt;
  exit 1&lt;br /&gt;
fi&lt;br /&gt;
cd $workdir</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=26531#26531</comments>
                                        <author>nordle</author>
                                        <pubDate>Sun Jul 02, 2006 9:27 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=26531#26531</guid>
                                      </item>
                                      <item>
                                        <title>Re: Bash script only works once</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=26529#26529</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5312'&gt;TheDoctor&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Sun Jul 02, 2006 9:19 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      &lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
# script to rename a collection of photos in a single dir&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;What is the working directory? &amp;#40;include the final backslash&amp;#41;&amp;quot;&lt;br /&gt;
read workdir&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;What is the base filename?&amp;quot;&lt;br /&gt;
read basefile&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;What is the number of the last picture?&amp;quot;&lt;br /&gt;
read filecount&lt;br /&gt;
&lt;br /&gt;
cd $workdir&lt;br /&gt;
for file in *&lt;br /&gt;
do&lt;br /&gt;
let filecount=filecount+1&lt;br /&gt;
mv $file &amp;quot;$basefile$filecount.jpg&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
You've not said what your input was in each of your two cases.&lt;br /&gt;
&lt;br /&gt;
A couple of points:&lt;br /&gt;
&lt;br /&gt;
You don't check that you've pointed to the working directory that you've put the files into. Are you sure you didn't mistype it? The error loks suspiciously like what you get if you try the script in an empty directory.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
for file in *; do &lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
is the same as what yu've got</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=26529#26529</comments>
                                        <author>TheDoctor</author>
                                        <pubDate>Sun Jul 02, 2006 9:19 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=26529#26529</guid>
                                      </item>
                                      <item>
                                        <title>RE: Bash script only works once</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=26526#26526</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=167'&gt;nordle&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Sun Jul 02, 2006 9:06 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      for file in *; do&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, you can add &lt;br /&gt;
set -x&lt;br /&gt;
at the start of your script to enable debugging, makes it easy to see eactly what the problem is...most of the time &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=26526#26526</comments>
                                        <author>nordle</author>
                                        <pubDate>Sun Jul 02, 2006 9:06 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=26526#26526</guid>
                                      </item>
                                      <item>
                                        <title>Bash script only works once</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=26518#26518</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=356'&gt;2tux-zx7r&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Sun Jul 02, 2006 7:37 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      After months of nagging from my missus I have gotten round to sorting out the near thousand digital pictures we have been storing on our hard disk&lt;br /&gt;
&lt;br /&gt;
I've written a little script so that once I've collected related pictures with nifty and memorable titles like p100101.jpg into a temporary folder I can batch rename them to something that makes sense. I'm no programming guru and getting the following to work took me about two hours today !&lt;br /&gt;
&lt;br /&gt;
So it worked on a load of test pictures and I was made up. But the second test failed with the error message:&lt;br /&gt;
&lt;br /&gt;
mv: cannot stat `*': No such file or directory&lt;br /&gt;
&lt;br /&gt;
Here's my bash script&amp;#058;&lt;br /&gt;
&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
# script to rename a collection of photos in a single dir&lt;br /&gt;
&lt;br /&gt;
echo &quot;What is the working directory? (include the final backslash)&quot;&lt;br /&gt;
read workdir&lt;br /&gt;
&lt;br /&gt;
echo &quot;What is the base filename?&quot;&lt;br /&gt;
read basefile&lt;br /&gt;
&lt;br /&gt;
echo &quot;What is the number of the last picture?&quot;&lt;br /&gt;
read filecount&lt;br /&gt;
&lt;br /&gt;
cd $workdir&lt;br /&gt;
for file in * &lt;br /&gt;
do&lt;br /&gt;
	let filecount=filecount+1&lt;br /&gt;
	mv $file &quot;$basefile$filecount.jpg&quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
Someone please tell me what I've done wrong&lt;br /&gt;
&lt;br /&gt;
John</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=26518#26518</comments>
                                        <author>2tux-zx7r</author>
                                        <pubDate>Sun Jul 02, 2006 7:37 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=26518#26518</guid>
                                      </item></channel></rss>