码迷,mamicode.com
首页 > 系统相关 > 详细

Shell的输入输出

时间:2015-07-05 14:58:31      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

通过使用read命令,可以实现从终端中输入内容后输出或执行运算

1 #!/bin/bash
2 #Author: blacksonny
3 #Copyright (c)
4 #Script follows here:
5 
6 echo "How old are you?"
7 read age
8 echo "age is " $age

以上代码会首先输出一个 [How old are yoy?],这时终端等待输入,当我们输入18这个数字(会将18赋值给age)并键入回车后,屏幕输出结果为age is 18

如下运行结果:

kk@kk-pc ~/shell
$ sh ./inout.sh
How old are you?
18
age is  18

Shell的输入输出

标签:

原文地址:http://www.cnblogs.com/blacksonny/p/4622077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!