Afficher un message
Vieux 21/08/2006, 11h24   #4
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
 
Page generated in 0,04391 seconds with 9 queries