提供的脚本在executiong-Grep不匹配时抛出错误

时间:2017-10-25 05:41:43

标签: shell

当我运行以下脚本时,我得到错误grep:Unmatched(或(

我也无法理解在shell脚本中执行的grep,用于从web获取单词的定义。

#!/bin/sh

# define - given a word, return its definition from dictionary.com

url="http://www.cogsci.princeton.edu/cgi-bin/webwn2.0?stage=1&word="

if [ $# -ne 1 ] ; then
echo "Usage: $0 word" >&2 
exit 1
fi

lynx -source "$url$1" | \
grep -E '(^[[:digit:]]+\.| has [[:digit:]]+$)' | \
sed 's/<[^>]*>//g' |
( while read line 
do 
if [ "${line:0:3}" = "The" ] ; then
  part="$(echo $line | awk '{print $2}')"
  echo ""
  echo "The $part $1:"
else
  echo "$line" | fmt | sed 's/^/  /g'
fi
done
) 

exit 0

0 个答案:

没有答案