Bash: Variable type confusion

Net Llama! netllama
Mon May 17 11:39:07 PDT 2004


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



More information about the Linux-users mailing list