Re: shel script problem regarding arrays
On 21 Aug 2006 02:35:54 -0700, Danish wrote:
[...]
> integer expression expected
> ./ls2.sh: line 18: [: 0
[...]
> n=0
> while [ $n -lt ${#array1[@]} ]
> do
> [ "${array[$n]}" -ne "${array1[$n]}" ] && echo "Error"
> done
[...]
Chances are the file is in MSDOS text formant where lines are
terminated by the <CR><LF> sequence instead of <LF> as Unix
expects it.
So $n contains "0<CR>" which is not a valid integer expression.
Use sed l < your-script to identify where the CRs are.
Note that $n is not incremented in your loop.
You're using arrays in a sh script. Arrays are not a standard sh
feature, you should specify which specific sh implementation
that script is intended for as you rely on non-standard
extension.
So
#! /bin/bash -
or
#! /bin/ksh -
....
--
Stephane
|