Книга: The Linux Command Line
Назад: 28. Reading Keyboard Input
Дальше: Index

, we constructed some simple menus and built the logic used to act on a user’s selection. To do this, we used a series of if commands to identify which of the possible choices had been selected. This type of construct appears frequently in programs, so much so that many programming languages (including the shell) provide a flow-control mechanism for multiple-choice decisions., we see the logic used to act on a user’s selection

shows some valid patterns.

Here is an example of patterns at work:

#!/bin/bash  read -p "enter word > "  case $REPLY in          [[:alpha:]])     echo "is a single alphabetic character." ;;          [ABC][0-9])      echo "is A, B, or C followed by a digit." ;;          ???)             echo "is three characters long." ;;          *.txt)           echo "is a word ending in '.txt'" ;;          *)               echo "is something else." ;; esac

© RuTLib.com 2015-2018