Linux Shell接收键盘输入

1.read命令格式

read [选项] [变量名]

选项:

-p “提示信息”:在等待read输入时,输出提示信息

-t “秒数”: read命令会一致等待用户输入,使用此选项可以指定等待时间

-n “字符数”: read命令只接受指定的字符数,就会执行

-s: 隐藏输入的数据,适用于机密信息的输入

2.代码典例

创建keyinput.sh文件,并输入下面代码:

#!/bin/bashread -t 30 -p "Please input your username:" username
echo -e "\n"
echo "username is $username"read -s -t 30 -p "Please input your passsword:" password
echo -e "\n"
echo "password is $password"read -n 1 -t 30 -p "Please input your gender[M/F]" gender
echo -e "\n"
echo "gender is $gender"

赋予keyinput.sh文件可执行权限,并运行keyinput.sh文件

chmod 755 keyinput.sh
./test.sh

效果如下图:

在这里插入图片描述


获取更多技术干货,请访问大土土随笔
如果本文对您有所帮助,请关注微信公众号“捷创源科技”。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/546283.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

机房收费重构之总结篇

《机房收费重构》之路终于接近了尾声,这么一个月的时间做梦都在敲代码。总结《机房收费重构》的道路需要从学习方法,注意问题,知识总结三方面来进行! 《机房收费重构》之路的背景: 1.设计模式: 设计模式的思…

带有Python示例的math.exp()方法

Python math.exp()方法 (Python math.exp() method) math.exp() method is a library method of math module, it is used to get the number in exponential form, it accepts a number and returns the number in the exponential format (if the number is x, it returns e*…

想快速拥有个人网站?来试试这个...

一、简介Hugo 是Go语言实现的一款静态网站生成器。它简单、易用、高效、易扩展、快速部署。相比较其他静态网站生成器,它的优点有这几点:项目构建特别快主题目录与站点目录结构一样配置文件为*.toml 格式,语法常简单易懂,没有缩进…

android 类ios actionsheet效果

1.http://blog.csdn.net/zhaoxy_thu/article/details/17733389 2. https://github.com/ojhariddhish/actionsheetdemo

带有Python示例的math.cos()方法

Python math.cos()方法 (Python math.cos() method) math.cos() method is a library method of math module, it is used to get the cosine of the number radians, it accepts a number returns the cosine of the given number radians. math.cos()方法是数学模块的库方法&…

Linux Debian下突然所有命令未找到,显示bash: xxxxx: command not found的解决办法

出现这个问题是因为系统的环境变量没有正确配置造成的。 在终端内执行下面命令,确实可以解决办法,但是当关掉当前的shell窗口或者重启Linux的时候,我就发现又出现了找不到命令的错误。 export PATH/bin:/usr/bin:$PATH下面分享下彻底解决方…

Java对象都是在堆上分配空间吗?答案竟然是...

作者 l Hollis来源 l Hollis(ID:hollischuang)Java作为一种面向对象的,跨平台语言,其对象、内存等一直是比较难的知识点,所以,即使是一个Java的初学者,也一定或多或少的对JVM有一些了…

c+pow函数的头文件_pow()函数以及C ++中的示例

cpow函数的头文件C pow()函数 (C pow() function) pow() function is a library function of cmath header (<math.h> in earlier versions), it is used to find the raise to the power, it accepts two arguments and returns the first argument to the power of th…

正则表达式 使用分支

正则表达式是非常有用的文本检索工具&#xff0c;这是一个非常简单而全面的教程正则表达式30分钟入门教程。这一篇教程&#xff0c;可以作为快速学习的工具。正则表达式&#xff0c;可能用的不是非常多&#xff0c;只是在Linux下&#xff0c;分析代码时候&#xff0c;用的比较多…

Python pandas读取csv txt excel和mysql数据库文件方法

# _*_coding:utf-8_*_ import os import pandas as pd import pymysql# Press the green button in the gutter to run the script. if __name__ __main__:strFilePath1 os.getcwd() "/天气.csv"df1 pd.read_csv(strFilePath1)print(df1)strFilePath2 os.getcwd…

服务器运行容器工具大盘点!

服务器到底是什么&#xff1f;服务器的硬件好理解&#xff0c;其实就是一台性能、稳定性、扩展性等等比我们普通个人PC强的一台机器而已&#xff0c;它也需要搭载操作系统&#xff0c;比如有专门的Windows Server或者各种Linux发行版系统。只不过咱这里很多小伙伴可能还是处于学…

python函数示例_使用Python中的示例的input()函数

python函数示例Python input()函数 (Python input() function) input() function is a library function, it is used to get the user input, it shows given message on the console and wait for the input and returns input value in string format. input()函数是一个库函…

Python pandas DateFrame查询数据df.loc的5种方法

# _*_coding:utf-8_*_ import pandas as pd# 自定义函数 def func(df):return df[temperature] < 32# Press the green button in the gutter to run the script. if __name__ __main__:data {date: [2022-08-21, 2022-08-22, 2022-08-23],weather: ["晴", &quo…

想读Spring源码?先从这篇「 极简教程」开始吧...

为什么要阅读源码&#xff1f;这是一个有趣的问题&#xff0c;类似的问题还有&#xff0c;为什么要看书&#xff1f;为什么要爬山&#xff1f; 这也是一个哲学问题&#xff0c;我想每个人都有不同的答案&#xff0c;下面我是对阅读源码好处的一些思考。 &#xff08;PS&#x…

Python pandas DateFrame新增数据列

下面代码在Linux下运行 # _*_coding:utf-8_*_ import os import pandas as pd# 自定义函数 def func(x):if x[temperature] > 30:return 高温if x[temperature] < 10:return 低温return 常温# Press the green button in the gutter to run the script. if __name__ __…

python函数示例_带Python示例的float()函数

python函数示例Python float()函数 (Python float() function) float() function is a library function in Python, it is used to get a float value from a given number or a string. It accepts either a string (that should contain a number) or a number and returns …

ALP规则的验证

实验1&#xff1a;ALP规则的验证实验目标创建本地用户jack、tom、mike,创建本地组group1&#xff0c;并把所建的用户加入到group1中&#xff0c;通过ALP规则实现以上用户对e:\share\1.txt 文件内容读取和写入权限实验环境略实验步骤一、 创建本地用户jack、tom、mike右击计算机…

6大分布式定时任务对比

作者 | sharedCode来源 | blog.csdn.net/u012394095/article/details/79470904分布式定时任务简介 把分散的&#xff0c;可靠性差的计划任务纳入统一的平台&#xff0c;并实现集群管理调度和分布式部署的一种定时任务的管理方式&#xff0c;叫做分布式定时任务。常见开源方案 e…

Python利用pandas获取每行最大值和最小值

知识点 1.找出每一行最大值和对应的列索引&#xff1a; #找出每行最大值对应的索引 df[max_idx]df.idxmax(axis1) #取出该最大值 df[max_val]df.max(axis1)2.找出每一行最小值和对应的列索引&#xff1a; # 找出每行最小值对应的索引 df[min_idx]df.idxmin(axis1) # 取出该最…

一文搞懂 ThreadLocal 原理

当多线程访问共享可变数据时&#xff0c;涉及到线程间同步的问题&#xff0c;并不是所有时候&#xff0c;都要用到共享数据&#xff0c;所以就需要线程封闭出场了。数据都被封闭在各自的线程之中&#xff0c;就不需要同步&#xff0c;这种通过将数据封闭在线程中而避免使用同步…