lookup.sh
来自「Shall高级编程」· Shell 代码 · 共 41 行
SH
41 行
#!/bin/bash# lookup: Does a dictionary lookup on each word in a data file.file=words.data # Data file from which to read words to test.echowhile [ "$word" != end ] # Last word in data file.do # ^^^ read word # From data file, because of redirection at end of loop. look $word > /dev/null # Don't want to display lines in dictionary file. lookup=$? # Exit status of 'look' command. if [ "$lookup" -eq 0 ] then echo "\"$word\" is valid." else echo "\"$word\" is invalid." fi done <"$file" # Redirects stdin to $file, so "reads" come from there.echoexit 0# ----------------------------------------------------------------# Code below line will not execute because of "exit" command above.# Stephane Chazelas proposes the following, more concise alternative:while read word && [[ $word != end ]]do if look "$word" > /dev/null then echo "\"$word\" is valid." else echo "\"$word\" is invalid." fidone <"$file"exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?