- 论坛徽章:
- 0
|
现有如下程序:- #!/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之间必须加入一个空行呢?
|
|