agram2.sh

来自「Shall高级编程」· Shell 代码 · 共 47 行

SH
47
字号
#!/bin/bash# agram2.sh# Example of nested command substitution.#  Uses "anagram" utility#+ that is part of the author's "yawl" word list package.#  http://ibiblio.org/pub/Linux/libs/yawl-0.3.2.tar.gz#  http://personal.riverusers.com/~thegrendel/yawl-0.3.2.tar.gzE_NOARGS=66E_BADARG=67MINLEN=7if [ -z "$1" ]then  echo "Usage $0 LETTERSET"  exit $E_NOARGS         # Script needs a command-line argument.elif [ ${#1} -lt $MINLEN ]then  echo "Argument must have at least $MINLEN letters."  exit $E_BADARGfiFILTER='.......'         # Must have at least 7 letters.#       1234567Anagrams=( $(echo $(anagram $1 | grep $FILTER) ) )#          $(     $(  nested command sub.    ) )#        (              array assignment         )echoecho "${#Anagrams[*]}  7+ letter anagrams found"echoecho ${Anagrams[0]}      # First anagram.echo ${Anagrams[1]}      # Second anagram.                         # Etc.# echo "${Anagrams[*]}"  # To list all the anagrams in a single line . . .#  Look ahead to the "Arrays" chapter for enlightenment on#+ what's going on here.# See also the agram.sh script for an example of anagram finding.exit $?

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?