0

I wrote this code in bash scripting and can't figure out what the error is. The terminal say: 15: [:Illegal number: 0+1

This is the code: #!/bin/bash min=999 max=0 n=0 num=0 promedio=0 i=0

echo "Ingrese n"
read n
while [$i -le $n] ---> LINE 15 IN THE ACTUAL SCRIPT, HERE IS THE ERROR I CANT FIND
do 
echo "Ingrese numero"
read num
if [$num -lt $min]
    then
        min=$num
fi
if [$num -gt $max]
    then 
        max=$num
fi
promedio=$promedio+$num
i=$i+1
done

media=$promedio/$n

echo "Mayor: $max"
echo "Menor: $min"
echo "Promedio: $media"

I tried many things but as I'm not an expert and I couldn't find any solution on the internet I am posting this question.

3
  • 1
    Spaces are not optional. [$i and [ "$i" are two different things. Commented Apr 22, 2024 at 20:22
  • 1
    Also, i=$i+1 should be i=$(( i + 1 )); your current code stores 1+1 when what you want to store is 2. The same is true for all the other places you want to do arithmetic operations. Commented Apr 22, 2024 at 20:22
  • 1
    Consider making a habit of running your code through shellcheck.net before asking questions here -- some editor integrations, like bash-lsp, can do this for you if you have shellcheck installed locally on your system. Commented Apr 22, 2024 at 20:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.