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( ...
随机推荐
- 记录日志(Log4Net)
一:Log4net的简单示例 1.新建控制台应用程序,右键属性,把其框架.NET Framework4 Client Profile 修改为.NET Framework4,此时项目中将会自动添加一个A ...
- 504 Gateway Timeout Error 502 Bad Gateway
总结 1. 502没有收到相应,或者收到了但不及时? cannot get a response in time 540收到了无效的响应 received an invalid response fr ...
- Locality-sensitive hashing Pr[m(Si) = m(Sj )] = E[JSˆ (Si, Sj )] = JS(Si, Sj )
A hash function that maps names to integers from 0 to 15. There is a collision between keys "Jo ...
- 使用Retrofit发送POST请求提交JSON数据
Retrofit官网:https://square.github.io/retrofit/ 示例如下 HttpService.java import okhttp3.RequestBody; impo ...
- 【题解】Cats Transport (斜率优化+单调队列)
[题解]Cats Transport (斜率优化+单调队列) # When Who Problem Lang Verdict Time Memory 55331572 Jun/09/2019 19:1 ...
- 【题解】[Ghd]
[题解]Ghd 一道概率非酋题? 题目很有意思,要我们选出大于\(\frac{n}{2}\)个数字使得他们的最大公约数最大. 那么我们若随便选择一个数字,他在答案的集合里的概率就大于\(0.5\)了. ...
- render 的执行流程
流程 : render 只能识别 字符串,对于其他的css,html,js,jquery样式是不能识别的,它会将文件中的内容解析称为字符串拿到前端页面,浏览器进行渲染. 例如 : # 视图函数 de ...
- java.lang.UnsupportedClassVersionError: com/dw/Function : Unsupported major.minor version 52.0
本地环境中有jdk7和jdk8,当把jdk8改为jdk7时,出现如下错误,是jdk版本的问题,在Properties-->JAVA Compiler-中的Compiler compliance ...
- P4474 王者之剑
P4474 王者之剑 题目大意 n*m的带权网格,任意选择起点开始时刻为0秒.以下操作,每秒按顺序执行 在第i秒开始的时候,在方格(x,y)上,获得(x,y)的值 在偶数秒,周围四格的值清零 每秒可选 ...
- UVA11426 GCD - Extreme (II) —— 欧拉函数
题目链接:https://vjudge.net/problem/UVA-11426 题意: 求 ∑ gcd(i,j),其中 1<=i<j<=n . 题解:1. 欧拉函数的定义:满足 ...