Syntax error for the For loop in the shell (syntax Error:bad for loop variable)

Source: Internet
Author: User

This error occurs because some Linux systems use Ash to compile shell scripts by default, as is my machine, but the scripts I write should be executed with bash. Although I noted in the beginning #!/bin/bash, as if it is still the default to find Ash, it is very frustrating. Search the internet for a bit, find two solutions: 1, modify script 2, modify the system default execution Shell tool

The first kind of practice is that the original for loop is similar to this for ((I=1; i<3; i++)) and changed to something like this: for I in ' seq 1000 ', which was copied from a Netizen's blog, I don't know if it's equivalent. But look at the latter full face black question mark, after all, I write more Java, so I do not know what the latter mean.

The second way to do this is to execute a command sudo dpkg-reconfigure dash, after executing this command there will be a scary page, full-screen background to red, a hint box. The idea is that our system chooses dash by default to improve the system's performance and boot speed (as if there is one), choose Dash as the default execution Shell tool? (PIT) We can choose the no option. I did not dare to choose, because I do not know what will be a moth after the election.

But after writing this, I am ready to change, because I have a lot of in the original for the loop, I do not know how to change them to bash execution of the way.

OK, if you change and then want to change back, directly re-execute the above command, choose Yes. Easy

Syntax error for the For loop in the shell (syntax Error:bad for loop variable)

Related Article

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.