pb.sh

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

SH
51
字号
#!/bin/bash# pb.sh: phone book# Written by Rick Boivie, and used with permission.# Modifications by ABS Guide author.MINARGS=1     #  Script needs at least one argument.DATAFILE=./phonebook              #  A data file in current working directory              #+ named "phonebook" must exist.PROGNAME=$0E_NOARGS=70   #  No arguments error.if [ $# -lt $MINARGS ]; then      echo "Usage: "$PROGNAME" data-to-look-up"      exit $E_NOARGSfi      if [ $# -eq $MINARGS ]; then      grep $1 "$DATAFILE"      # 'grep' prints an error message if $DATAFILE not present.else      ( shift; "$PROGNAME" $* ) | grep $1      # Script recursively calls itself.fiexit 0        #  Script exits here.              #  Therefore, it's o.k. to put              #+ non-hashmarked comments and data after this point.# ------------------------------------------------------------------------Sample "phonebook" datafile:John Doe        1555 Main St., Baltimore, MD 21228          (410) 222-3333Mary Moe        9899 Jones Blvd., Warren, NH 03787          (603) 898-3232Richard Roe     856 E. 7th St., New York, NY 10009          (212) 333-4567Sam Roe         956 E. 8th St., New York, NY 10009          (212) 444-5678Zoe Zenobia     4481 N. Baker St., San Francisco, SF 94338  (415) 501-1631# ------------------------------------------------------------------------$bash pb.sh RoeRichard Roe     856 E. 7th St., New York, NY 10009          (212) 333-4567Sam Roe         956 E. 8th St., New York, NY 10009          (212) 444-5678$bash pb.sh Roe SamSam Roe         956 E. 8th St., New York, NY 10009          (212) 444-5678#  When more than one argument is passed to this script,#+ it prints *only* the line(s) containing all the arguments.

⌨️ 快捷键说明

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