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