1
#!/bin/bash
x=1
while [ "$x" -lt 20 ]
do
    echo "$x"
    x=("$x" * 5);
done

Getting error as syntax error near unexpected token `done' and getting output as 11111111111....

ilkkachu
  • 138,973

1 Answers1

2

Use the right syntax for the calculation:

x=$((x*5))
pLumo
  • 22,565
  • Hi pLumo, Thanks that worked for the syntax.Can you please let me know how to get the multiples of 5 including 1 and 100. so that i can move further. – raju kiran Mar 24 '20 at 13:30
  • Again: learn your 5 times table. 0 x 5 is 0; 1 * 5 is 5; there is no integer that you multiply by 5 to get 1. Just echo 1 at the top, because it is an irregular series anyway. Also, if you want 100, you need to permit the iteration where x is 20, so use -le instead of -lt. Or you might just try: echo 1 {5..100..5}; or: for x in 1 {5..100..5}; do echo $x; done; and see which you prefer. – Paul_Pedant Mar 24 '20 at 15:37
  • #!/bin/bash x=1

    echo "$x"

    while [ $x -lt 20 ] do x=$(( x*5 )); echo "$x" (( x++ )) done The output I'm getting is 1 5 30 155.

    – raju kiran Mar 26 '20 at 15:03