登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

SeaRiver Blog

实力才是你一生最好的依靠!

 
 
 

日志

 
 

几个简单的交互shell脚本实例(bash)  

2008-05-22 11:05:32|  分类: shell |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

#!/bin/bash


echo -e "Are you happy? \c"
read answer
echo "$answer is the right response."

echo -e "What is your full name? \c"
read first middle last
echo "Hello  $first $middle $last"


echo -n "Where do you work? "
read
echo I guess $REPLY keeps you busy!


read -p "Enter your job title: "
echo "I thought you might be an $REPLY."


echo -n "Who are your best friends? "
read -a friends
echo "Say hi to ${friends[0]}."

trap 'echo "Not press Ctrl+C"'  2    //屏蔽掉Ctrl+C功能。

echo
echo "Press entery key to continue, or Ctrl+C to abort..."   //充许按Ctrl+C来终止程序继续执行
read junk
clear

注:上面两个不能同时在一个脚本里出现.否则就没有意义了


result:
==========================================
[root@jp-test-apache yuhj]# sh read.sh
Are you happy? yes
yes is the right response.
What is your full name?
[root@jp-test-apache yuhj]# sh read.sh
Are you happy? happy
happy is the right response.
What is your full name? yu h j
Hello  yu h j
Where do you work? China
I guess China keeps you busy!
Enter your job title: test
I thought you might be an test.
Who are your best friends? people
Say hi to people.

Press entery key to continue, or Ctrl+C to abort...
Not press Ctrl+C

  评论这张
 
阅读(817)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018