The error "declare not found" is displayed when the shell script is run in Ubuntu.

Source: Internet
Author: User
Tags echo command
-------------------------------------------------------------------------------
Declare not found error (dash in Ubuntu): # Why, # DASH: @ 2010-Mar-25
-------------------------------------------------------------------------------

This problem only occurs in Ubuntu! This type of problem does not exist when Debian is installed, because only
Ubuntu replaces the default bash with Dash. After using Debian for one day, it seems that
Get the "Windows 7" in the Linux World. I just got started with Linux. I wonder if there is any problem with my opinion.
Different opinions may be raised. Thank you!
-----------------

When learning shell scripts, two examples run abnormally. For example, I'm at the test-dash.sh foot
The following content is entered:
Echo-e "trekshot. \ A \ n"
Declare-I number = 7
Echo $ number
Running with the sh test-bash.sh in Ubuntu displays the following prompt:
-E trekshot.

Test-dash.sh: 2: declare: not found:

There are two problems:
A. How can I print the echo parameter '-e?
B. Why is the prompt "declare: Not Found" displayed in a simple integer declaration statement "?

1.
The reason for this problem is not that the Code itself is incorrect, but that of the Ubuntu system. When writing a script
The line often needs to write the following content :#! /Bin/bash. This is to declare the shell used by the script, because
There is not only one shell in Linux, but the syntax of each shell is different. The echo command
Is because the sh command does not understand the syntax, that is, the current use is not bash.
Ming:

Get the attributes of related files in/bin:
-Rwxr-XR-x 1 Root 725136 2008-05-13 bash
-Rwxr-XR-x 1 Root 87924 2008-06-21 dash
Lrwxrwxrwx 1 Root 4 2010-03-25 14:29 sh-> dash

This indicates that when executing the sh test-dash.sh, we are using a command called "Dash" (note sh
Instead of the bash statement declared in the first line of the script. This is the reason for the above phenomenon. In fact, such
If you run the bash test-dash.sh command, the above two errors won't appear at all.

2.
After the Ubuntu 6.10, replace the previous bashshell
Dash (to be verified). The following text is included in the description for setting DASH:

The default/bin/sh shell On Debian and Debian-based systems is Bash.

However, since the default shell is required to be POSIX-compliant, any
Shell that conforms to POSIX, such as Dash, can serve as/bin/sh. You may
Wish to do this because Dash is faster and smaller than bash.

The default shell is bash shell, but it can be used as long as it is compatible with POSIX.
Dash is faster and smaller than bash, so Ubuntu has installed dash.

3.
How can we remove Dash and use the default Bash? Run the following command:
Sudo dpkg-reconfigure dash
This command is to re-configure the installed package. In the menu (dash-bash-sh.png), select whether to link sh

To dash (install dash as/bin/sh ?) Select No.

Figure 1: Configure dash in Ubuntu

From: http://www.cnblogs.com/Trekshot/archive/2010/03/29/ubuntu-shell-bash-dash.html

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.