Variable expansion issue

Variable expansion issue

am 24.01.2008 03:43:54 von bdorsey63

What is the issue is that if the in directory has matching files, the
$filelist in the for loop expands to have those file names. I do not
want that list. I want the list file to loop test* stuff*, such that,
in the lftp it would first mget test*, then go get stuff*.

Can any one help with this?

The sname.list can be

test*
stuff*

Here is the code:
filelist=`cat sname.list`
datadirin=/my/data/in

cd $datadirin
for i in $filelist
do
lftp $lftp_debug $server << End-Of-Session
user $username $password
cd $directory
echo "getting $i"
mget -E $i
bye
End-Of-Session
RC=$?
done

Re: Variable expansion issue

am 24.01.2008 05:28:56 von Barry Margolin

In article
<8d5439af-7544-4a4b-af74-ee1822f2a2bf@i7g2000prf.googlegroups.com>,
bdorsey63@gmail.com wrote:

> What is the issue is that if the in directory has matching files, the
> $filelist in the for loop expands to have those file names. I do not
> want that list. I want the list file to loop test* stuff*, such that,
> in the lftp it would first mget test*, then go get stuff*.
>
> Can any one help with this?
>
> The sname.list can be
>
> test*
> stuff*
>
> Here is the code:
> filelist=`cat sname.list`
> datadirin=/my/data/in
>
> cd $datadirin
> for i in $filelist
> do
> lftp $lftp_debug $server << End-Of-Session
> user $username $password
> cd $directory
> echo "getting $i"
> mget -E $i
> bye
> End-Of-Session
> RC=$?
> done

I don't think there's any way to expand $filelist that will break on the
whitespace but not expand the wildcards. So instead of using a
variable, have your loop read the lines:

cd $datadirin
while read i
do
...
done < sname.list

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: Variable expansion issue

am 24.01.2008 12:57:04 von bdorsey63

On Jan 23, 10:28=A0pm, Barry Margolin wrote:
> In article
> <8d5439af-7544-4a4b-af74-ee1822f2a...@i7g2000prf.googlegroups.com>,
>
>
>
>
>
> =A0bdorse...@gmail.com wrote:
> > What is the issue is that if the in directory has matching files, the
> > $filelist in the for loop expands to have those file names. I do not
> > want that list. I want the list file to loop test* stuff*, such that,
> > in the lftp it would first mget test*, then go get stuff*.
>
> > Can any one help with this?
>
> > The sname.list can be
>
> > test*
> > stuff*
>
> > Here is the code:
> > filelist=3D`cat sname.list`
> > datadirin=3D/my/data/in
>
> > cd $datadirin
> > =A0 =A0 =A0 for i in =A0$filelist
> > =A0 =A0 =A0 =A0 do
> > =A0 =A0 =A0 =A0 lftp $lftp_debug =A0$server =A0<< End-Of-Session
> > =A0 =A0 =A0 =A0 =A0 user $username $password
> > =A0 =A0 =A0 =A0 =A0 cd $directory
> > =A0 =A0 =A0 =A0 =A0 echo "getting $i"
> > =A0 =A0 =A0 =A0 =A0 mget -E =A0$i
> > =A0 =A0 =A0 =A0 =A0 bye
> > End-Of-Session
> > =A0 =A0 =A0 =A0RC=3D$?
> > =A0 =A0done
>
> I don't think there's any way to expand $filelist that will break on the
> whitespace but not expand the wildcards. =A0So instead of using a
> variable, have your loop read the lines:
>
> cd $datadirin
> while read i
> do
> =A0 ...
> done < sname.list
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***- Hide=
quoted text -
>
> - Show quoted text -

I tried your suggestion, this works but the lftp section will not
work. the << causes a syntax error. I would have to handle the inside
loop differntly. (Not sure how)

How about reseting the internal shell directory variable just before
expansion. Becauserhis would guarentee no file to be found and the
default behavior would be to not expand. And then inside the lftp do a
local change directory.

Re: Variable expansion issue

am 25.01.2008 02:43:06 von Barry Margolin

In article
,
bdorsey63@gmail.com wrote:

> On Jan 23, 10:28 pm, Barry Margolin wrote:
> > In article
> > <8d5439af-7544-4a4b-af74-ee1822f2a...@i7g2000prf.googlegroups.com>,
> >
> >
> >
> >
> >
> >  bdorse...@gmail.com wrote:
> > > What is the issue is that if the in directory has matching files, the
> > > $filelist in the for loop expands to have those file names. I do not
> > > want that list. I want the list file to loop test* stuff*, such that,
> > > in the lftp it would first mget test*, then go get stuff*.
> >
> > > Can any one help with this?
> >
> > > The sname.list can be
> >
> > > test*
> > > stuff*
> >
> > > Here is the code:
> > > filelist=`cat sname.list`
> > > datadirin=/my/data/in
> >
> > > cd $datadirin
> > >       for i in  $filelist
> > >         do
> > >         lftp $lftp_debug  $server  << End-Of-Session
> > >           user $username $password
> > >           cd $directory
> > >           echo "getting $i"
> > >           mget -E  $i
> > >           bye
> > > End-Of-Session
> > >        RC=$?
> > >    done
> >
> > I don't think there's any way to expand $filelist that will break on the
> > whitespace but not expand the wildcards.  So instead of using a
> > variable, have your loop read the lines:
> >
> > cd $datadirin
> > while read i
> > do
> >   ...
> > done < sname.list
> >
> > --
> > Barry Margolin, bar...@alum.mit.edu
> > Arlington, MA
> > *** PLEASE post questions in newsgroups, not directly to me ***
> > *** PLEASE don't copy me on replies, I'll read them in the group ***- Hide
> > quoted text -
> >
> > - Show quoted text -
>
> I tried your suggestion, this works but the lftp section will not
> work. the << causes a syntax error. I would have to handle the inside
> loop differntly. (Not sure how)

<< should work the same inside a while loop as it does in a for loop. I
just did a little test to confirm this. So I suspect you messed
something up -- please post the new script.

> How about reseting the internal shell directory variable just before
> expansion. Becauserhis would guarentee no file to be found and the
> default behavior would be to not expand. And then inside the lftp do a
> local change directory.

You could try that. But depending on a wildcard not to match anything
is not very safe.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: Variable expansion issue

am 25.01.2008 02:48:14 von bdorsey63

On Jan 24, 5:57=A0am, bdorse...@gmail.com wrote:
> On Jan 23, 10:28=A0pm, Barry Margolin wrote:
>
>
>
>
>
> > In article
> > <8d5439af-7544-4a4b-af74-ee1822f2a...@i7g2000prf.googlegroups.com>,
>
> > =A0bdorse...@gmail.com wrote:
> > > What is the issue is that if the in directory has matching files, the
> > > $filelist in the for loop expands to have those file names. I do not
> > > want that list. I want the list file to loop test* stuff*, such that,
> > > in the lftp it would first mget test*, then go get stuff*.
>
> > > Can any one help with this?
>
> > > The sname.list can be
>
> > > test*
> > > stuff*
>
> > > Here is the code:
> > > filelist=3D`cat sname.list`
> > > datadirin=3D/my/data/in
>
> > > cd $datadirin
> > > =A0 =A0 =A0 for i in =A0$filelist
> > > =A0 =A0 =A0 =A0 do
> > > =A0 =A0 =A0 =A0 lftp $lftp_debug =A0$server =A0<< End-Of-Session
> > > =A0 =A0 =A0 =A0 =A0 user $username $password
> > > =A0 =A0 =A0 =A0 =A0 cd $directory
> > > =A0 =A0 =A0 =A0 =A0 echo "getting $i"
> > > =A0 =A0 =A0 =A0 =A0 mget -E =A0$i
> > > =A0 =A0 =A0 =A0 =A0 bye
> > > End-Of-Session
> > > =A0 =A0 =A0 =A0RC=3D$?
> > > =A0 =A0done
>
> > I don't think there's any way to expand $filelist that will break on the=

> > whitespace but not expand the wildcards. =A0So instead of using a
> > variable, have your loop read the lines:
>
> > cd $datadirin
> > while read i
> > do
> > =A0 ...
> > done < sname.list
>
> > --
> > Barry Margolin, bar...@alum.mit.edu
> > Arlington, MA
> > *** PLEASE post questions in newsgroups, not directly to me ***
> > *** PLEASE don't copy me on replies, I'll read them in the group ***- Hi=
de quoted text -
>
> > - Show quoted text -
>
> I tried your suggestion, this works but the lftp section will not
> work. the << causes a =A0syntax error. I would have to handle the inside
> loop differntly. (Not sure how)
>
> How about reseting the internal shell directory variable just before
> expansion. Becauserhis would guarentee no file to be found and the
> default behavior would be to not expand. And then inside the lftp do a
> local change directory.- Hide quoted text -
>
> - Show quoted text -

I found the error with the while read. The << End-Of-Session and its
match had a unknown character.

So... more testing.

Re: Variable expansion issue

am 26.01.2008 00:02:11 von bdorsey63

On Jan 24, 7:48=A0pm, bdorse...@gmail.com wrote:
> On Jan 24, 5:57=A0am, bdorse...@gmail.com wrote:
>
>
>
>
>
> > On Jan 23, 10:28=A0pm, Barry Margolin wrote:
>
> > > In article
> > > <8d5439af-7544-4a4b-af74-ee1822f2a...@i7g2000prf.googlegroups.com>,
>
> > > =A0bdorse...@gmail.com wrote:
> > > > What is the issue is that if the in directory has matching files, th=
e
> > > > $filelist in the for loop expands to have those file names. I do not=

> > > > want that list. I want the list file to loop test* stuff*, such that=
,
> > > > in the lftp it would first mget test*, then go get stuff*.
>
> > > > Can any one help with this?
>
> > > > The sname.list can be
>
> > > > test*
> > > > stuff*
>
> > > > Here is the code:
> > > > filelist=3D`cat sname.list`
> > > > datadirin=3D/my/data/in
>
> > > > cd $datadirin
> > > > =A0 =A0 =A0 for i in =A0$filelist
> > > > =A0 =A0 =A0 =A0 do
> > > > =A0 =A0 =A0 =A0 lftp $lftp_debug =A0$server =A0<< End-Of-Session
> > > > =A0 =A0 =A0 =A0 =A0 user $username $password
> > > > =A0 =A0 =A0 =A0 =A0 cd $directory
> > > > =A0 =A0 =A0 =A0 =A0 echo "getting $i"
> > > > =A0 =A0 =A0 =A0 =A0 mget -E =A0$i
> > > > =A0 =A0 =A0 =A0 =A0 bye
> > > > End-Of-Session
> > > > =A0 =A0 =A0 =A0RC=3D$?
> > > > =A0 =A0done
>
> > > I don't think there's any way to expand $filelist that will break on t=
he
> > > whitespace but not expand the wildcards. =A0So instead of using a
> > > variable, have your loop read the lines:
>
> > > cd $datadirin
> > > while read i
> > > do
> > > =A0 ...
> > > done < sname.list
>
> > > --
> > > Barry Margolin, bar...@alum.mit.edu
> > > Arlington, MA
> > > *** PLEASE post questions in newsgroups, not directly to me ***
> > > *** PLEASE don't copy me on replies, I'll read them in the group ***- =
Hide quoted text -
>
> > > - Show quoted text -
>
> > I tried your suggestion, this works but the lftp section will not
> > work. the << causes a =A0syntax error. I would have to handle the inside=

> > loop differntly. (Not sure how)
>
> > How about reseting the internal shell directory variable just before
> > expansion. Becauserhis would guarentee no file to be found and the
> > default behavior would be to not expand. And then inside the lftp do a
> > local change directory.- Hide quoted text -
>
> > - Show quoted text -
>
> I found the error with the while read. The << End-Of-Session and its
> match had a unknown character.
>
> So... more testing.- Hide quoted text -
>
> - Show quoted text -

The while read i loop work.
Changing directory to a blnak work to.

I will go with the while loop.

THANKS