Bash: Variable type confusion
Joel Hammer
Joel
Mon May 17 11:39:08 PDT 2004
If I use a variable as an integer, then use as a string, it doesn't go
back to being an integer nicely.
Oh well. Either I had forgotten about this behavior or I never ran across it
before. Almost the same thing at my age.
Joel
On Sun, Oct 20, 2002 at 05:59:16PM -0400, Joel Hammer wrote:
> What version of bash are you using?
>
> I have having a lot of trouble with variable typing.
> My version of bash is:
> GNU bash, version 2.04.0(1)-release (i686-pc-linux-gnu)
> Copyright 1999 Free Software Foundation, Inc.
>
>
> Joel
>
>
> On Sun, Oct 20, 2002 at 02:23:16PM -0700, Net Llama! wrote:
> > On 10/20/02 13:53, Joel Hammer wrote:
> >
> > > I have always thought that bash does the right thing when it evaluates
> > > variables.
> > > Until today.
> > > This bit of script works as expected:
> > > k=0
> > > for i in `dir -1 *jpg`
> > > do
> > > k=$((k+1))
> > > echo $k
> > > done
> > >
> > > It prints out the numbers from 1 to whatever the number of jpg's in the
> > > directory.
> > >
> > > However, this fails:
> > > k=0
> > > for i in `dir -1 *jpg`
> > > do
> > > k=$((k+1))
> > > [ "$k" -eq 10 ] && k=x <---The problem.
> > > echo $k
> > > done
> >
> > Both of these work the same for me, using bash.
> >
> > --
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > L. Friedman netllama at linux-sxs.org
> > Linux Step-by-step & TyGeMo: http://netllama.ipfox.com
> >
> > 2:20pm up 8 days, 2:38, 1 user, load average: 0.11, 0.40, 0.41
> >
> > _______________________________________________
> > Linux-users mailing list
> > Linux-users at linux-sxs.org
> > Unsubscribe/Suspend/Etc -> http://www.linux-sxs.org/mailman/listinfo/linux-users
> _______________________________________________
> Linux-users mailing list
> Linux-users at linux-sxs.org
> Unsubscribe/Suspend/Etc -> http://www.linux-sxs.org/mailman/listinfo/linux-users
More information about the Linux-users
mailing list