Syntax error: Bad For loop variable solution
A simple shell script is written in Ubuntu, and the value of 1 + 2 + 3... + 100 is calculated using the for... do... done structure. An error is always returned.
Script:
#! /Bin/bash
# Information
Path =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Bin
Export path
Read-P "Please input a num" Num
Sum = 0
For (a = 0; A <= $ num; A = a + 1 ))
Do
Sum = $ ($ sum + $ ))
Done
Echo "the sum is => $ sum"
Exit 0
Error syntax error: Bad For Loop Variable
Solution: sudo dpkg-reconfigure dash
Select No from the selected items.
Starting from Ubuntu 6.10, UBUNTU replaces the default bash shell with the dash shell. It shows that the/bin/sh link is down with/bin/dash instead of the traditional/bin/bash.
Ubuntu edgy is the first version released with Dash as the default shell, which seems to be affected by Debian. There is an official explanation in the Wiki, https://wiki.ubuntu.com/dashasbinsh. the main reason is that dashis smaller, runs faster, and is compatible with posix.
However, the current problem is that the shell replacement causes many script errors. After all, many of the current scripts are not 100% POSIX compatible.
As mentioned in the Wiki, how can we change the default shell back to bash?
Run sudo dpkg-reconfigure dash on the terminal
Select No