[] Problems in Shell script programming in Ubuntu

Source: Internet
Author: User
According to the shell programming example of "laruence's house cooking", there is an inexplicable problem. For example, the file name is sh06.sh :#! /Bin/bash # Program: # Thisprogramwillshowtheuser 'schice # History: #2010/08/01 cnhjqFirstreleasePATH =/B

According to the shell programming example of "laruence's house cooking", there is an inexplicable problem.
For example, the file name is sh06.sh:
#! /Bin/bash
# Program:
# This program will show the user's choice
# History:
#2010/08/01 cnhjq First release
PATH =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Bin
Export PATH

Read-p "Please input (Y/N):" yn
["$ Yn" = "Y"-o "$ yn" = "y"] & echo "OK, continue." & exit 0
["$ Yn" = "N"-o "$ yn" = "n"] & echo "oh, interrupt! "& Exit 0
Echo "I don't know what is you choice" & exit 0

During execution, the [: 10: y: unexpected operator
In the terminal, the command in shell is directly input by line, and the operation is successful. I can't help but sigh again about the strange problem.

Finally, I found the answer on the Internet:
First:
The default sh in Ubuntu is connected to dash, and an error occurs because of the incompatibility between dash and bash. During execution, you can replace sh with the bash file name. sh for execution (such as bash sh06.sh ). Successful.
What is dash! Ask baidu or google!
Modify sh to connect to bash by default:
Sudo dpkg-reconfigure dash
Or this should also be possible:
Alias sh = 'bash'

Second:
See the results of others' discussions in a forum.
Change = To =. dash uses = to judge that the string is equal.

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.