I'd like to add a few comments about the OP script:
1) Please use ***[code][/code] tags
*** around your code and data, to preserve the original formatting and to improve readability. Do not
use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
"~" is an interactive alias. In a script it's usually better to use the built-in "$HOME" variable.
a. QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS
. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.
(Actually, this script is ok, since $file has been previously set to a safe value. But do it anyway to get into the habit! )
b. The line as written is completely unneeded. There's no need set up a fancy file descriptor in most scripts, and even then you'd probably use a different descriptor number.
while read line...done
Again, instead of using an exec
redirect to feed the while loop
, just use 'done <"$file"
' to redirect the file contents into it directly. It's cleaner and makes the code easier to comprehend.
value=`expr $value + 1`;
a. $(..) is highly recommended over `..`
is wholly unnecessary in any modern shell. integer-based arithmetic
Try a simple "(( value++ ))
cp $sourcedir/"$image" $targetdir;
The quoting is all wrong here; you're leaving $sourcedir and $targetdir completely unprotected. The general rule of thumb is to simply quote the longest
string possible. e.g. ...
cp "$sourcedir/$image" "$targetdir"