1.14不使用回车键来读取n个字符
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个字符的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- GOM通区插件-支持GOM绝对路径-读取配置项-分割字符等功能。不定期更新
A-A+ 2019年07月19日 Gom引擎 阅读 45 views 次 [@Main] #IF #SAY [<读配置项/@读配置项>] [<写配置项/@写配置项>] [& ...
- 常见错误0xCCCCCCCCC 读取字符串的字符时出错及其引申。
问题描述在一个函数调用中,使用二级指针作为函数参数,传递一个字符串指针数组,但是在访问的时候,却出现了运行时错误,具体表现为"0xCCCCCCCC 读取字符串的字符时出错". 第一 ...
- 14.swoole学习笔记--异步读取文件
<?php //异步读取文件 swoole_async_readfile(__DIR__."/1.txt",function($filename,$content){ ech ...
- [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 ...
- Unicode文件读取 出现隐藏字符 (大坑)
C#读取文件..分析时发现应该15位的.. str.Lenght 却 16位.. 字符串复制出来一位位的数..就是15位.. 纳闷中突然想起来会不会是隐藏字符.. 输出 str[0].ToBytes( ...
随机推荐
- LRM-00109: could not open parameter file
SQL>startup ...
- jQuery学习笔记(7)--表格展开关闭
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...
- javascript中replace( )方法的使用——有博主已经讲过了,但里面有一小丢丢知识错误,挺重要的部分,我就重提下,以免初学者弄错
阿里面试题:说出以下函数的作用是?空白区域应该填写什么? 其实这个问题http://www.phpstudy.net/b.php/105983.html解释的已经非常好了,思路也很顺,容易理解,本文将 ...
- 【题解】P3796【模板】AC自动机(加强版)
[题解]P3796 [模板]AC自动机(加强版) 记录当前\(cnt\)是第几个"星".记录第几个串是对应着第几个星. 这里补充一点对于\(AC\)自动机的理解.可能一直有个问题我 ...
- Django创建项目及app
主要环境为python3.5,编译环境为pycharm 首先已经安装好Django相关的组件 1.首先创建Django程序: windows系统下pycharm创建步骤: File->New P ...
- cordova 插件创建
peng@PENG-PC /E/_My_File_____/_work/MyCode/myCode/cordova-workspace/plugman-test/ABCD $ npm install ...
- Java for LeetCode 127 Word Ladder
Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...
- css浏览器兼容问题集锦
表单按钮用input type=submit和a链接两者表现不一致的问题 表单的输入框.文本.验证码图片没有对齐 IE6/7中margin失效 IE6中margin双边距 1.问题: 表单按钮用inp ...
- 现代JS中的流程控制:详解Callbacks 、Promises 、Async/Await
JavaScript经常声称是_异步_.那是什么意思?它如何影响发展?近年来这种方法有何变化? 请思考以下代码: result1 = doSomething1(); result2 = doSomet ...
- Java基础知识整理之static修饰属性
static 关键字,我们在开发用的还是比较多的.在<Java编程思想>有下面一段话 static 方法就是没有 this 的方法.在 static 方法内部不能调用非静态方法,反过来是可 ...