Ubuntu: script error for while loop



Question:

I'm getting the below error while i executing the bash script.

#!/bin/bash    mynum=1    while [ $mynum -le 10 ]  do      echo $mynum      mynum= $(( $mynum + 1 ))      sleep 0.5  done  

error:

$./wl  1  ./wl: line 8: 2: command not found  1  ./wl: line 8: 2: command not found  1  ./wl: line 8: 2: command not found  1  ./wl: line 8: 2: command not found  1  ./wl: line 8: 2: command not found  1  ./wl: line 8: 2: command not found  1  ./wl: line 8: 2: command not found  1  ./wl: line 8: 2: command not found  


Solution:1

The correct way for incrementing variable is as follows (How to increment a variable in bash?)

#!/bin/bash  mynum=1  while [ $mynum -le 10 ]  do      echo $mynum      mynum=$((mynum+1))      sleep 0.5  done  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »