⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lookup.sh

📁 Shall高级编程
💻 SH
字号:
#!/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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -