read是一个重要的bash命令,它用于从键盘或标准输入中读取文本。可以使用read以交互的形式读取来自用户的输入,不过read能做的远不止这些。很多编程语言的输入库都是从键盘读取输入,且只有回车键按下的时候,才标志着输入完毕,很多情形不是这样的,比如输入结束与否是基于字符数或某个特定字符来决定的。

read命令提供了一种不需要按回车键就能搞定任务的方法。

1、借助read的各种选项来实现不同的效果。

下面的语句从输入中读取n个字符并存入变量variable_name;

read -n number_of_chars variable_name

eg:

$ read -n 2 var

$ echo $var

2)用无回显的方式读取密码:

read -s var

3)显示提示信息:

read -p "Enter input:" var

4)在特定时限内读取输入:

read -t timeout var

如:$read -t 2 var  #在2秒内将键入的字符串读入变量var

5)用特定的定界符作为输入行的结束

read -d delim_char var

eg:$ read -d ":" var

$hello:#var被设置为hello

1.14不使用回车键来读取n个字符的更多相关文章

  1. [LeetCode] Read N Characters Given Read4 用Read4来读取N个字符

    The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actua ...

  2. [Swift]LeetCode157.用Read4来读取N个字符 $ Read N Characters Given Read4

    The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actua ...

  3. [Swift]LeetCode158. 用Read4来读取N个字符II $ Read N Characters Given Read4 II

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

  4. [LeetCode] 157. Read N Characters Given Read4 用Read4来读取N个字符

    The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actua ...

  5. GOM通区插件-支持GOM绝对路径-读取配置项-分割字符等功能。不定期更新

    A-A+ 2019年07月19日 Gom引擎 阅读 45 views 次   [@Main] #IF #SAY [<读配置项/@读配置项>] [<写配置项/@写配置项>] [& ...

  6. 常见错误0xCCCCCCCCC 读取字符串的字符时出错及其引申。

    问题描述在一个函数调用中,使用二级指针作为函数参数,传递一个字符串指针数组,但是在访问的时候,却出现了运行时错误,具体表现为"0xCCCCCCCC 读取字符串的字符时出错". 第一 ...

  7. 14.swoole学习笔记--异步读取文件

    <?php //异步读取文件 swoole_async_readfile(__DIR__."/1.txt",function($filename,$content){ ech ...

  8. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

  9. Unicode文件读取 出现隐藏字符 (大坑)

    C#读取文件..分析时发现应该15位的.. str.Lenght 却 16位.. 字符串复制出来一位位的数..就是15位.. 纳闷中突然想起来会不会是隐藏字符.. 输出 str[0].ToBytes( ...

随机推荐

  1. rtmp直播拉流客户端EasyRTMPClient设计过程中时间戳问题汇总

    EasyRTMPClient 简介 EasyRTMPClient是EasyDarwin流媒体团队开发.提供的一套非常稳定.易用.支持重连接的RTMPClient工具,以SDK形式提供,接口调用非常简单 ...

  2. vs2013工程下的各个文件和文件夹的作用

    1 ipch文件夹 用来加速编译,里面存放的是precompiled headers,即预编译好了的头文件. 头文件也是需要编译的,比如需要处理#ifdef,需要替换宏以及需要include其它头文件 ...

  3. To discount or not to discount in reinforcement learning: A case study comparing R learning and Q learning

    https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume4/kaelbling96a-html/node26.html [平均-打折奖励] Schwa ...

  4. 观察OnPaint与OnIdle与OnSize事件

    import wx class SketchWindow(wx.Window): def __init__(self, parent, ID): wx.Window.__init__(self, pa ...

  5. ubuntu16.04+cuda8.0+cudnn5.0+caffe

    ubuntu安装过程(硬盘安装)http://www.cnblogs.com/zhbzz2007/p/5493395.html“但是千万不要用麒麟版!!!比原版体验要差很多!!!”开关机的时候电脑最上 ...

  6. 我的Android进阶之旅------>如何在多个LinearLayout中添加分隔线

    如果要适合于所有的Android版本,可以在多个LinearLayout放置用于显示分隔线的View.例如,放一个ImageView组件,然后将其背景设为分隔线的颜色或图像,分隔线View的定义代码如 ...

  7. Coursera公开课Functional Programming Principles in Scala习题解答:Week 2

    引言 OK.时间非常快又过去了一周.第一周有五一假期所以感觉时间绰绰有余,这周中间没有假期仅仅能靠晚上加周末的时间来消化,事实上还是有点紧张呢! 后来发现每堂课的视频还有相应的课件(Slide).字幕 ...

  8. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

  9. TCP服务器端和客户端程序设计【转】

    本文转载自:http://blog.csdn.net/yueguanghaidao/article/details/7035248# 版权声明:本文为博主原创文章,未经博主允许不得转载. 一.实验目的 ...

  10. oracle数据库如何备份一张表

    --用户名:tms--创建表ts_dictionary的备份create table ts_dictionary_20160715 as select * from ts_dictionary; 补充 ...