shell脚本编程

来源:百度知道 编辑:UC知道 时间:2024/05/21 13:00:02
#!/usr/bin/bash

#================================================#
# Script Name: phoneadd #
# By: Your initials here #
# Date: Today`s date #
# Purpose: A shell script that sets up a #
# loop to add new employees to the #
# corp_phones file. #
# Command Line: phoneadd #
#================================================#

trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3
phonefile=~/Project6*/source/corp_phones 这里是将文件corp_phones的地址给变量phonefile吗?
looptest=y
while [ $looptest = y ]
do
clear
bold=$(tput smso)
offbold=$(tput rmso)
echo $bold
tput cup 1 4; echo "Corporate Phone List Additions"
echo $offbold
tput cup 2 4; echo "=============================="
tput cup 4 4; echo "Phone Number: "
tput cup 5 4; echo "Last Name : "
tput cup 6 4

tput cup 12 4; echo "Add Another? (y)es or (q)quit: "
当你输入 y 或 q 的时候,然后就执行下而的语句:
tput cup 4 18; read phonenum 这句就将你输入的 y 或 q 赋给变量phonenum
接下来的就是判断你输的是什么,要是 q 话就退出,这里的退出不是退出while循环,只是退出tput cup 12 4; echo "Add Another? (y)es or (q)quit: " 这一步,即不再输其它的.如果要退出while循环的话要加break ,如果说是 y 的话,它仅仅是给phonenum 赋了个变量,什么也没有做,我看后面的也没有再提到phonenum这个变量,我想一定还有其它的代码吧!
然后就接着执行下面的
tput cup 5 18; read lname
tput cup 6 18; read fname
tput cup 7 18; read midinit
tput cup 8 18; read deptno
tput cup 9 18; read jobtitle
tput cup 10 18; read datehired

#Check to see if last name is not a blank before you write to disk

if [ "$lname" > " " ]
then
echo "$phonenum:$lname:$fname:$midinit:$deptno:$jobtitle:$datehired" >> $phonefile
fi

还有下面的一段代码:

tput cup 12 33; read looptest
if [ "$looptest" = "q" ]
then
clear;