Solution to failure to execute script files using sh in Ubuntu

Source: Internet
Author: User
I recently started to learn the LinuxShell language and read the Private food of laruence. For the "Basic Linux Private food Learning for laruence (Third edition) PDF High Definition", see http://www.linuxidc.net/thread-2268-1-1.html. There are two methods to execute the shell script: 1. Set the execution attribute: chmod755file for execution (if it is already in the current directory ):.

I recently started to learn the Linux Shell language.

Look at the birds brother private dish, "Bird brother Linux private dish basic learning (the third edition) PDF High Definition" Download see http://www.linuxidc.net/thread-2268-1-1.html. There are two methods to execute shell scripts:

1. Set the execution attribute: chmod 755 file

Run (if it is already in the current directory):./file

2. Run the command using sh file.

However, Ubuntu 11.10 installed in vmware cannot be executed.

  1. #! /Bin/bash
  2. Declare-I s
  3. For (I = 1; I <= 100; I = I + 1 ))
  4. Do
  5. S = s + I
  6. Done
  7. Echo "The count is ==> $ s"

When the second method is used for execution, the following occurs:

Test04_for.sh: 1: declare: not found
Test04_for.sh: 3: Syntax error: Bad for loop variable

Solution:

Enter:

Sudo dpkg-reconfigure dash

Select "NO" on the displayed page.

Then you can run it correctly.

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

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.