????????????????????????ο?????
????[root@localhost ~]
????# ./note.sh
????Phone number?
????556
????Name?
????Janine
????Issue?
????Mouse was broken.
????[root@localhost ~]
????# cat data.txt
????987/Jimmy/Keybord issue.
????556/Janine/Mouse was broken.
????[root@localhost ~]
????#
??????????????????????????????????????????????????ū??Щ??????????????á????????????????????date????????????????????????????????
????[root@localhost ~]
????# date
????Thu Apr 23 21:33:14 EEST 2015 <---- date???????????
????[root@localhost ~]
????# date "+%Y.%m.%d %H:%M:%S"
????2015.04.23 21:33:18 <---- ???????????
?????м????????????????????????????????????????£?????????`??????????????????????????~????????λ????
????[root@localhost ~]
????# cat note.sh
????#!/bin/bash
????now=`date "+%Y.%m.%d %H:%M:%S"`
????echo "Phone number?"
????read phone
????echo "Name?"
????read name
????echo "Issue?"
????read issue
????echo "$now/$phone/$name/$issue">>data.txt
????[root@localhost ~]
????# ./note.sh
????Phone number?
????123
????Name?
????Jim
????Issue?
????Script hanging.
????[root@localhost ~]
????# cat data.txt
????2015.04.23 21:38:56/123/Jim/Script hanging.
????[root@localhost ~]
????#
??????…… ??????????????е????????????????????????????????read?????????read?????????????Щ?????????ù??????????????-p???????????
????[root@localhost ~]
????# cat note.sh
????#!/bin/bash
????now=`date "+%Y.%m.%d %H:%M:%S"`
????read -p "Phone number: " phone
????read -p "Name: " name
????read -p "Issue: " issue
????echo "$now/$phone/$name/$issue">>data.txt
???????????????????????????????????????????????????man read?? man echo?? man date?? man ……
??????????????????????????
????[root@localhost ~]
????# ./note.sh
????Phone number: 321
????Name: Susane
????Issue: Mouse was stolen
????[root@localhost ~]
????# cat data.txt
????2015.04.23 21:38:56/123/Jim/Script hanging.
????2015.04.23 21:43:50/321/Susane/Mouse was stolen
????[root@localhost ~]
????#
????????????????棨???????μ?????У??????е????????LCTT ?????????? echo ????????????????????? -n ???????????С???
???????
??????????????????????????????????????綽???????ζ??????У?????????鷳????????????Щ????????????????????
????[root@localhost ~]
????# cat note.sh
????#!/bin/bash
????while true
????do
????read -p "Phone number: " phone
????now=`date "+%Y.%m.%d %H:%M:%S"`
????read -p "Name: " name
????read -p "Issue: " issue
????echo "$now/$phone/$name/$issue">>data.txt
????done
???????????????read phone??now=date?е?λ?á???????????????????綽????????????????????????????????У?????????κ????? now ????????洢??????к??????????????????????????κ?п?????20??????????????
????[root@localhost ~]
????# ./note.sh
????Phone number: 123
????Name: Jim
????Issue: Script still not works.
????Phone number: 777
????Name: Daniel
????Issue: I broke my monitor
????Phone number: ^C
????[root@localhost ~]
????# cat data.txt
????2015.04.23 21:38:56/123/Jim/Script hanging.
????2015.04.23 21:43:50/321/Susane/Mouse was stolen
????2015.04.23 21:47:55/123/Jim/Script still not works.
????2015.04.23 21:48:16/777/Daniel/I broke my monitor
????[root@localhost ~]
????#
??????? ???????????????????????[Ctrl]+[C]????Shell?????^??? CTRL ????
??????ù???????
????????????????????????“??????????Frankenstein??”??????????????κ?к?????????????????????????????????????????????Ρ?????????????????cat???data.txt??
????[root@localhost ~]
????# cat data.txt
????2015.04.23 21:38:56/123/Jim/Script hanging.
????2015.04.23 21:43:50/321/Susane/Mouse was stolen
????2015.04.23 21:47:55/123/Jim/Script still not works.
????2015.04.23 21:48:16/777/Daniel/I broke my monitor
????2015.04.23 22:02:14/123/Jimmy/New script also not working!!!
????[root@localhost ~]
????#
??????????????????????????????cut??????cut????????г??????饗??????÷???“/”????????????????Σ?
????[root@localhost ~]
????# cat data.txt | cut -d"/" -f2
????123
????321
????123
????777
????123
????[root@localhost ~]
????#
????????????????????????????????????????sort??
????[root@localhost ~]
????# cat data.txt | cut -d"/" -f2|sort
????123
????123
????123
????321
????777
????[root@localhost ~]
????#
???????????μ??С????????????????-c????uniq????
????[root@localhost ~]
????# cat data.txt | cut -d"/" -f2 | sort | uniq -c
????3 123
????1 321
????1 777
????[root@localhost ~]
????#
??????????????????????????
????#!/bin/bash
????while true
????do
????read -p "Phone number: " phone
????now=`date "+%Y.%m.%d %H:%M:%S"`
????read -p "Name: " name
????read -p "Issue: " issue
????echo "$now/$phone/$name/$issue">>data.txt
????echo "===== We got calls from ====="
????cat data.txt | cut -d"/" -f2 | sort | uniq -c
????echo "--------------------------------"
????done
???????У?
????[root@localhost ~]
????# ./note.sh
????Phone number: 454
????Name: Malini
????Issue: Windows license expired.
????===== We got calls from =====
????3 123
????1 321
????1 454
????1 777
????--------------------------------
????Phone number: ^C
?????????????????????????裺
??????????
??????????????
?????洢??????
????????洢??????
????????????????е?????????????????????????????????????????????????洢???????в????Щ?????????????Щ???飬??????????switches/cases?????????????????????????????????shell??“??”???????????á?