Pay attention to spaces when writing shell.

Source: Internet
Author: User

Below is a simple Linux ShellCodeThe function is used to find the current directory and all its directories which contain the four characters "html" and print the file name, at first glance, there should be no problem with this code, but there are actually two problems. Let's take a look at the following code:

 
#! /Bin/shfor afile in 'Find. /-name "*" '; do # echo $ afile; if [-F "$ afile"]; then wordnum = 'cat $ afile | grep HTML | WC-l '; if [$ wordnum-GT 0]; Then ECHO $ afile; FI fidone

1. The first problem is that the value assignment statement cannot have spaces between the change and the value. The preceding sentence:

Wordnum = 'cat $ afile | grep HTML | WC-l ';
If you write it like this, it will certainly report an error. You must write it as follows:

Wordnum = 'cat $ afile | grep HTML | WC-l ';

2. The second problem is that there must be spaces between the square brackets of the IF statement and the judgment condition, as shown in this statement:

If [$ wordnum> 0]; then
There is a problem. It must be written as follows:

If [$ wordnum-GT 0]; then

 

Therefore, the correct syntax of the following shell should be as follows:

 
#! /Bin/sh for afile in 'Find. /-name "*" '; do # echo $ afile; if [-F "$ afile"]; then wordnum = 'cat $ afile | grep HTML | WC-l '; if [$ wordnum> 0]; Then ECHO $ afile; FI fi done
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.