On Tue, Jun 16, 2009 at 02:33:37PM +0000, Paul Schmehl wrote: > --On Tuesday, June 16, 2009 08:09:09 -0500 Carmel NY > <carmel...@hotmail.com> wrote: > > > > >I am attempting to write a simple Bash script that will find all the > >'*.pem' files in a directory structure and move them to another > >directory. It seems to work until I get to the copy part where it fails. > > > >My scripting skills are not that good. Perhaps someone could tell me > >what I am doing wrong. > > > >This is the script: > > > ># ! /usr/bin/env bash > > > ># Save the field separator > >oIFS=$IFS > > > ># Set it to line breaks > >IFS=$'\n' > > > >for i in $(find ./ -name "*.pem" -print); do > > > ># Get the basename > >BN=$(basename $i) > > > ># copy the file to another directory using the base name > >cp $i /usr/home/tmp/$BN > > > >done > > > ># Reset the IFS variable > >IFS=$oIFS > > > >exit > > > > When I write scripts, I test them on the commandline to see if they're > doing what I think they're doing. I don't get the $(find ....)
It does exactly the same as `command -a rgs`, but all characters between the parentheses are taken literally (in the backtick form, certain chars have special meaning, but not in the $() form.) > construction. You're invoking find from within a for loop to return a > value. Use backticks. > > This works. > > for i in `find ./ -name "*.pem" -print` > do > foo > bar > done It also works with the $() form, provided the target directory exists! Dan -- Daniel Bye _ ASCII ribbon campaign ( ) - against HTML, vCards and X - proprietary attachments in e-mail / \
pgp7aBx5Ctfjr.pgp
Description: PGP signature