Ubuntu prompts Syntax error: Bad for loop variable when performing arithmetic operations

Source: Internet
Author: User


Syntax error: Bad for loop variable solution: a simple shell script is written in Ubuntu .. do .. done Structure Calculation 1 + 2 + 3 ...... if the value is greater than 100, an error is always returned. Www.2cto.com Script :#! /Bin/bash # information PATH =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Binexport PATH read-p "Please input a num" numsum = 0for (a = 0; a <= $ num; a = a + 1 )) do sum = $ ($ sum + $ a) doneecho "the sum is => $ sum" exit 0 error Syntax error: Bad for loop variable solution:

Sudo dpkg-reconfigure dash select No www.2cto.com from the options of ubuntu 6.10, ubuntu will replace the previous default bash shell with the dash shell; the result is that/bin/sh links down/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, if he changes the default shell back to bash, the method is to execute sudo dpkg-reconfigure dash on the terminal and select no from the column csh159.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.