Write a simple shell script-For loop-Resolve error Syntax Error:bad for loop variable

Source: Internet
Author: User

To write a program that imports data in batches, learn to write shell scripts! Now learn to use!

============================================

1, the first simple for loop

#!/bin/bash
For I in 1 2 3 4;
Do
echo $i;
Done

2. Test for self-growing loops:

#!/bin/bash
for ((I=1; i<=5; i++)
Do
echo $i;
Done

If there is an error, no then skip:

Syntax Error:bad for loop variable

Reason: The code is not wrong for standard bash, because Ubuntu is doing the same with dash instead of the traditional bash in order to speed up the boot.

Workaround: Cancel Dash

Dpkg-reconfigure Dash

A bullet box appears, select No

Refer to the original details to resolve the error:

http://blog.csdn.net/yf210yf/article/details/9206185

3, Actual combat: Batch Import data

#!/bin/bash
for ((I=1; i<=1000; i++)
Do
Echo ' Curl http://localhost/test.php?page= $i & ';
Done

With echo you can see the output, and the output of "add-end-0" for my test.php program runs out once

Write a simple shell script-For loop-Resolve error 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.