我正在编写一个简单的Bash脚本来拼写,通过命令行检查一个单词。
这样做的方法是:
echo "word" | aspell -a然后,拼写输出如下所示:
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1)
*或者如果这个单词拼错了:
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1)
& wordd 29 0: word, wordy, worded, words, Ward, Wood, ward, woad, wood, wort, world, woody, wooed, weird, word's, Wed, wed, wot, we'd, who'd, odd, warded, wooded, worked, wormed, sword, wad, wordier, wold我的计划是在变量中捕获输出,如果单词是正确的,则不输出任何输出,如果拼写错误,则输出建议减去A拼写版本和拼写检查分数。
但是,奇怪的是,我当前目录的内容被添加到变量中。到目前为止,这是一个脚本:
RESULTS=$(echo $1 | aspell -a)
echo $RESULTS给脚本一个拼写错误的单词(即将$1设置为一个拼写错误的单词)给了我以下内容:
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1) & shipp 41 0: ship, shoppe, shop, shipper, chippy, chip, ships, Sharp, chirp, shape, sharp, sheep, shopper, choppy, hippo, hippy, supp, chop, shipped, hip, sip, ship's, shops, chipper, chippie, Sharpe, Sherpa, chappy, chirpy, shpt, shim, shin, shit, shiv, whip, chap, chimp, chips, shier, shop's, chip's(请注意,这一切都错在一行上)
并给出一个拼写正确的单词:
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1) Gemfile Gemfile.lock README.rdoc Rakefile app bin config config.ru db lib log public spell.sh test tmp vendor奇怪的是,添加了我当前目录(Gemfile、Gemfile.lock等)的内容。另外,这里也缺少换行符,包含拼写正确单词的星号的正确的A拼写输出也丢失了。
很明显我不知道巴什有什么事。有人知道怎么回事吗?
发布于 2014-11-27 22:23:51
您需要在echo中使用双引号,以防止命令aspell返回的星号的bash展开。
echo "$RESULTS"尝试以下命令并观察不同之处:
# echo "*"
# echo *阅读Filename Expansion中的3.5.8节巴什手册页
发布于 2014-11-27 22:19:25
尝试这样做:
RESULTS=$(echo "$1" | aspell -a | sed 1d)
[[ $RESULTS == \* ]] || echo "$RESULTS"https://stackoverflow.com/questions/27179350
复制相似问题