- 論壇徽章:
- 0
|
現(xiàn)有如下程序:- #!/bin/sh
- #set -x
- CACHE_PATH=/var/lib/HPCCSystems/mydropzone/cache/
- VERINT_PATH=/var/lib/HPCCSystems/mydropzone/verint/
- ESOON_PATH=/var/lib/HPCCSystems/mydropzone/esoon/
- HP_PATH=/var/lib/HPCCSystems/mydropzone/hp/
- ANS=yes
- ANS2=yes
- KWANS=yes
- KEYWORD=""
- CMD=""
- while [ "$ANS" = "yes" -o "$ANS" = "y" -o "$ANS" = "Y" ]
- do
- echo "Enter a folder name(cache[c], verint[v], esoon[e], hp[h]):"
- read NAME
- echo "Enter the key word:"
- read WORD
- echo "Do you need to input more key words? yes[y/Y] or no[n/N]"
- read KWANS
- while [ "$KWANS" = "yes" -o "$KWANS" = "y" -o "$KWANS" = "Y" ]
- do
- KEYWORD=$KEYWORD" grep "$WORD" | "
- echo "Enter the key word:"
- read WORD
- echo "Do you need to input more key words? yes[y/Y] or no[n/N]"
- read KWANS
- done
- CMD="find "$CACHE_PATH" -name \"*.*\" | xargs"$KEYWORD"more"
- echo $CMD
- echo "Continue? Enter yes[y/Y] or no[n/N]"
- read ANS
- echo ""
- done
復制代碼 注意第一個while和do之間,有個空行
我如果把這個空行刪除了,變成如下的代碼:- #!/bin/sh
- #set -x
- CACHE_PATH=/var/lib/HPCCSystems/mydropzone/cache/
- VERINT_PATH=/var/lib/HPCCSystems/mydropzone/verint/
- ESOON_PATH=/var/lib/HPCCSystems/mydropzone/esoon/
- HP_PATH=/var/lib/HPCCSystems/mydropzone/hp/
- ANS=yes
- ANS2=yes
- KWANS=yes
- KEYWORD=""
- CMD=""
- while [ "$ANS" = "yes" -o "$ANS" = "y" -o "$ANS" = "Y" ]
- do
- echo "Enter a folder name(cache[c], verint[v], esoon[e], hp[h]):"
- read NAME
- echo "Enter the key word:"
- read WORD
- echo "Do you need to input more key words? yes[y/Y] or no[n/N]"
- read KWANS
- while [ "$KWANS" = "yes" -o "$KWANS" = "y" -o "$KWANS" = "Y" ]
- do
- KEYWORD=$KEYWORD" grep "$WORD" | "
- echo "Enter the key word:"
- read WORD
- echo "Do you need to input more key words? yes[y/Y] or no[n/N]"
- read KWANS
- done
- CMD="find "$CACHE_PATH" -name \"*.*\" | xargs"$KEYWORD"more"
- echo $CMD
- echo "Continue? Enter yes[y/Y] or no[n/N]"
- read ANS
- echo ""
- done
復制代碼 就會報錯:
./test.sh: line 38: syntax error near unexpected token `done'
./test.sh: line 38: `done '
意思是最后一行的done沒認出來
請問while中套while,為什么第一個while和do之間必須加入一個空行呢?
|
|