Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jun 2009 16:16:26 +0100
From:      "Daniel Bye" <danielby@slightlystrange.org>
To:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: Problem with bash script
Message-ID:  <20090616151626.GD93430@torus.slightlystrange.org>
In-Reply-To: <7F04C88B7C6A39C7E1B6F366@utd65257.utdallas.edu>
References:  <BLU0-SMTP586D9F12148D0B6683B635933F0@phx.gbl> <7F04C88B7C6A39C7E1B6F366@utd65257.utdallas.edu>

next in thread | previous in thread | raw e-mail | index | archive | help

--JwB53PgKC5A7+0Ej
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Jun 16, 2009 at 02:33:37PM +0000, Paul Schmehl wrote:
> --On Tuesday, June 16, 2009 08:09:09 -0500 Carmel NY=20
> <carmel_ny@hotmail.com> wrote:
>=20
> >
> >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=3D$IFS
> >
> ># Set it to line breaks
> >IFS=3D$'\n'
> >
> >for i in $(find ./ -name "*.pem" -print); do
> >
> ># Get the basename
> >BN=3D$(basename $i)
> >
> ># copy the file to another directory using the base name
> >cp $i /usr/home/tmp/$BN
> >
> >done
> >
> ># Reset the IFS variable
> >IFS=3D$oIFS
> >
> >exit
> >
>=20
> When I write scripts, I test them on the commandline to see if they're=20
> doing what I think they're doing.  I don't get the $(find ....)=20

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=20
> value.  Use backticks.
>=20
> This works.
>=20
> for i in `find ./ -name "*.pem" -print`
> do
> foo
> bar
> done

It also works with the $() form, provided the target directory exists!

Dan

--=20
Daniel Bye
                                                                     _
                                              ASCII ribbon campaign ( )
                                         - against HTML, vCards and  X
                                - proprietary attachments in e-mail / \

--JwB53PgKC5A7+0Ej
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (FreeBSD)

iEYEARECAAYFAko3t0oACgkQixf5fBYiFmqVrACffBmCn76T5aud+KmMHFlQrcP2
1XcAn3KfajVpkGq3tioCe9+++k2wPYTD
=A/4y
-----END PGP SIGNATURE-----

--JwB53PgKC5A7+0Ej--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090616151626.GD93430>