关于cat用法的一点疑问?
发表于 : 2009-07-11 18:40
详见下面的代码,能否解释下cat的这种用法什么意思?
代码: 全选
cat <<MAYDAY
----------------------------------------------------------
User: $USER Host:$THIS_HOST DATE:$MYDATE
----------------------------------------------------------
1:List files in current directory
2:Use the vi editor
3:See who is on the system
H:Help screen
Q:Exit Menu
----------------------------------------------------------
MAYDAY
代码: 全选
#!/bin/bash
#menu
#set the date,user and hostname up
MYDATE=`date +%d/%m/%Y`
THIS_HOST=`hostname -s`
USER=`whoami`
#loop forever !
while :
do
#clear the screen
clear
#here documents starts here
cat <<MAYDAY
----------------------------------------------------------
User: $USER Host:$THIS_HOST DATE:$MYDATE
----------------------------------------------------------
1:List files in current directory
2:Use the vi editor
3:See who is on the system
H:Help screen
Q:Exit Menu
----------------------------------------------------------
MAYDAY
#here document finished
echo -e -n "\tEnter Your Choice [1,2,3,H,Q] >"
read CHOICE
case $CHOICE in
1) ls
;;
2) vi
;;
3) who
;;
H|h)
#use a here document for the help screen
cat <<MAYDAY
This is the help screen,nothing here yet to help you!
MAYDAY
;;
Q|q) exit 0
;;
*) echo -e "\t\007unknown user response"
;;
esac
echo -e -n "\tHit the return key to continue"
read DUMMY
done