当前位置: 首页 > news >正文

Linux shell编程学习笔记36:read命令

 *更新日志 

*2023-12-18 1.根据[美] 威廉·肖特斯 (Willian shotts)所著《Linux命令行大全(第2版)》
                        更新了-e、-i、-r选项的说明

                      2.更新了 2.8 的实例,增加了gif动图

                      3.补充了-i的应用实例 2.12

目录

  1. 目录
  2. 0 前言
  3. 1 read命令的功能、格式、返回值和注意
    1. 1.1 命令功能
    2. 1.2 命令格式
    3. 1.3 返回值
    4. 1.4 注意事项
  4. 2 命令应用实例
    1. 2.1 一次读入多个变量值
    2. 2.2 不指定变量名
    3. 2.3 测试read命令的返回值
    4. 2.3 指定输入时限并进行相应处理
    5. 2.4 -t 指定结束符
    6. 2.5 -n 指定输入字符个数
    7. 2.6 -N 指定输入字符个数
    8. 2.7 -s不回显来自终端的输入
    9. 2.8 -e使用命令补全功能
    10. 2.9 -r 允许输入的值中包含的反斜杠\也作为值输出
    11. 2.10 -a 读取数组值
    12. 2.11 -u指定文件说明符
    13. 2.12 -i 使用初始值

 

0 前言

在交互式编程中,有时我们需要用户先通过键盘来输入数据,然后程序根据用户输入的数据来做相应的处理。

在之前的学习中,我们已经使用read命令来读取用户通过键盘输入的数据,但对read命令没有做进一步的说明。

现在我们来研究一下read命令的详细用法。

1 read命令的功能、格式、返回值和注意

我们可以使用命令 help read  来查看seq命令的帮助信息:

purleEndurer @ bash ~ $ help read
read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
    Read a line from the standard input and split it into fields.
    
    Reads a single line from the standard input, or from file descriptor FD
    if the -u option is supplied.  The line is split into fields as with word
    splitting, and the first word is assigned to the first NAME, the second
    word to the second NAME, and so on, with any leftover words assigned to
    the last NAME.  Only the characters found in $IFS are recognized as word
    delimiters.
    
    If no NAMEs are supplied, the line read is stored in the REPLY variable.
    
    Options:
      -a array  assign the words read to sequential indices of the array
                variable ARRAY, starting at zero
      -d delim  continue until the first character of DELIM is read, rather
                than newline
      -e                use Readline to obtain the line in an interactive shell
      -i text   Use TEXT as the initial text for Readline
      -n nchars return after reading NCHARS characters rather than waiting
                for a newline, but honor a delimiter if fewer than NCHARS
                characters are read before the delimiter
      -N nchars return only after reading exactly NCHARS characters, unless
                EOF is encountered or read times out, ignoring any delimiter
      -p prompt output the string PROMPT without a trailing newline before
                attempting to read
      -r                do not allow backslashes to escape any characters
      -s                do not echo input coming from a terminal
      -t timeout        time out and return failure if a complete line of input is
                not read withint TIMEOUT seconds.  The value of the TMOUT
                variable is the default timeout.  TIMEOUT may be a
                fractional number.  If TIMEOUT is 0, read returns success only
                if input is available on the specified file descriptor.  The
                exit status is greater than 128 if the timeout is exceeded
      -u fd             read from file descriptor FD instead of the standard input
    
    Exit Status:
    The return code is zero, unless end-of-file is encountered, read times out,
    or an invalid file descriptor is supplied as the argument to -u.
readarray: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
    Read lines from a file into an array variable.
    
    A synonym for `mapfile'.
readonly: readonly [-aAf] [name[=value] ...] or readonly -p
    Mark shell variables as unchangeable.
    
    Mark each NAME as read-only; the values of these NAMEs may not be
    changed by subsequent assignment.  If VALUE is supplied, assign VALUE
    before marking as read-only.
    
    Options:
      -a        refer to indexed array variables
      -A        refer to associative array variables
      -f        refer to shell functions
      -p        display a list of all readonly variables and functions
    
    An argument of `--' disables further option processing.
    
    Exit Status:
    Returns success unless an invalid option is given or NAME is invalid.
purleEndurer @ bash ~ $ 

 1.1 命令功能

从标准输入或-u 选项指定的文件描述符读取一行。该行被拆分为多个字段,就像单词拆分一样,第一个单词分配给第一个 变量,第二个单词分配给第二个 变量,依此类推,任何剩余的单词都分配给最后一个 变量。如果未提供 变量名,则读取的行存储在 REPLY 变量中。

只有在 $IFS 中找到的字符才会被识别为单词分隔符。

1.2 命令格式

 read [-ers] [-a 索引数组名] [-d 结束符] [-i 初始字符串] [-n 字符数] [-N 字符数] [-p 提示字符串] [-t 超时秒数] [-u 文件描述符] [变量名 ...]

  • 选项说明 
选项说明备注
-a 索引数组名将读取的单词从下标零开始分配给数组名指定的 索引数组,默认是以空格为分割符array
-d 结束符读取数据,直至结束符,而不是换行符delimiter
-e使用 在交互式 shell 中获取用户输入行,在输入的时候可以使用命令补全功能
-i 初始字符串

使用初始字符串作为 用户输入行 的初始值

需要与-e选项一起使用

initialize
-n 字符数在读取指定的字符数后返回,除非遇到定界符、换行符或读取超时,定界符包括\t(tab键)。number
-N 字符数

在读取指定的字符数后返回,除非遇到 EOF 或读取超时

与 -n 不同的是,-N 会忽略任何定界符。

number
-p 提示字符串先输出提示字符串,再读取数据prompt
-r不允许反斜杠转义任何字符raw mode
-s不回显来自终端的输入silence
-t 超时秒数

指定输入字符的等待时间。

如果在 超时秒数 内未读取完整的输入行,则超时并返回失败。
TMOUT变量的值是默认超时秒数。

超时秒数 可以是小数。
如果 超时秒数 为 0,则仅当指定的文件描述符上有可用的输入时,读取才会返回成功。
如果超过超时,则退出状态大于 128

timeout
-u 文件描述符从指定的文件描述符读入数据use

1.3 返回值

命令正常执行时返回值为零,

如果遇到文件末尾、读取超时或提供无效文件描述符作为 -u 的参数时,返回值不为零。

如果读取超时,返回值 将 大于 128。

1.4 注意事项

  • 变量名列表 应该放在 命令的最后。
  • 变量名之间以空格分隔。
  • -i选项需要与-e选项一起使用才有用

2 命令应用实例

2.1 一次读入多个变量值

例:提示用户输入3个整数,作为a、c、c 三个变量的值

purpleEndurer @ bash ~ $ read -p "Enter there integers:" a  b c
Enter there integers:1 2 3
purpleEndurer @ bash ~ $ echo a=$a b=$b c=$c
a=1 b=2 c=3
purpleEndurer @ bash ~ $ read -p "Enter there integers:" a  b c
Enter there integers:1 2 3 4 5 6
purpleEndurer @ bash ~ $ echo a=$a b=$b c=$c
a=1 b=2 c=3 4 5 6
purpleEndurer @ bash ~ $ 

当我们输入1 2 3 这三个整数后,变量a的值为1,变量b的值为2,变量c的值为3。

当我们输入1 2 3 4 5 6 这六个整数后,由于我们只给了a、b、c三个变理名,所以变量a的值为1,变量b的值为2,而变量c的值为:3 4 5 6。

2.2 不指定变量名

例:提示用户输入3个整数,但没指定变量名

purpleEndurer @ bash ~ $ echo $REPLY

purpleEndurer @ bash ~ $ read -p "Enter there integers:"
Enter there integers:1 2 3
purpleEndurer @ bash ~ $ echo $REPLY 
1 2 3
purpleEndurer @ bash ~ $ 

由于我们没有指定变量名,所以输入的值1 2 3保存在变量REPLY中。

2.3 测试read命令的返回值

例:提示用户输入名字,输入时间限定为10秒钟

purpleEndurer @ bash ~ $ read -t 10 -p "Enter your name:"
Enter your name:pe
purpleEndurer @ bash ~ $ echo $?
0
purpleEndurer @ bash ~ $ read -t 10 -p "Enter your name:"
Enter your name:purpleEndurer @ bash ~ $ echo $?
142
purpleEndurer @ bash ~ $ read -t 10 -p "Enter your name:"
Enter your name:purpleEndurer @ bash ~ $ echo $?
1
purpleEndurer @ bash ~ $ read -t 10 -p "Enter your name:"
Enter your name:^C
purpleEndurer @ bash ~ $ echo $?
130
purpleEndurer @ bash ~ $ 

当我们在10秒钟内输入用户名pe并回车,read命令正常执行,返回值为0

当我们未在10秒钟内输入用户名,read命令返回值为142,大于128

当我们输入^D时,read命令返回值为1

当我们输入^C时,read命令返回值为130

2.3 指定输入时限并进行相应处理

例:编写一个脚本,提示用户在5秒钟内输入名字,如果用户输入名字,则对用户进行问候,否则提示用户没有输入名字。

脚本内容如下:

read  -t 5 -p "Enter you name in 5 seconds:" name # 提示用户在5秒钟内输入名字并保存在变量name中
if [ $? == 0 ]; then                              # 如果用户在5秒钟内输入了名字,那么read命令返回值为0echo Hello, $name.                             # 对用户进行问候
elseecho -e "\nYou do not enter your name."        # 提示用户没有输入名字
fi

purpleEndurer @ bash ~ $ cp /dev/stdin a.sh
read  -t 5 -p "Enter you name in 5 seconds:" name
if [ $? == 0 ]; then
   echo Hello, $name.
else
   echo -e "\nYou do not enter your name."
fi

purpleEndurer @ bash ~ $ cat a.sh
read  -t 5 -p "Enter you name in 5 seconds:" name
if [ $? == 0 ]; then
   echo Hello, $name.
else
   echo -e "\nYou do not enter your name."
fi
purpleEndurer @ bash ~ $ . a.sh
Enter you name in 5 seconds:pe
Hello, pe.
purpleEndurer @ bash ~ $ . a.sh
Enter you name in 5 seconds:
You do not enter your name.
purpleEndurer @ bash ~ $ 

2.4 -t 指定结束符

例 读取用户输入值存入变量a,指定#作为结束符

purpleEndurer @ bash ~ $ read -d '#' a
ab#purpleEndurer @ bash ~ $ echo $a
ab
purpleEndurer @ bash ~ $ 

 

当我们输入ab#时,读取结束。变量a的值为ab。

2.5 -n 指定输入字符个数

例 读取5个字符,分别保存到变量a和b

purpleEndurer @ bash ~ $ read -n 5 a b
12345purpleEndurer @ bash ~ $ echo a=$a b=$b
a=12345 b=
purpleEndurer @ bash ~ $ read -n 5 a b
12 34purpleEndurer @ bash ~ $ echo a=$a b=$b
a=12 b=34
purpleEndurer @ bash ~ $ read -n 5 a b
1       234purpleEndurer @ bash ~ $ echo a=$a b=$b
a=1 b=234
purpleEndurer @ bash ~ $ read -n 5 a b
12
purpleEndurer @ bash ~ $ echo a=$a b=$b
a=12 b=
purpleEndurer @ bash ~ $ read -n 5 a b
123^C
purpleEndurer @ bash ~ $ echo a=$a b=$b
a=12 b=
purpleEndurer @ bash ~ $ 

当我们输入12345时,变量a的值为12345,变量b值为空

当我们输入12空格34时,变量a的值为12,变量b值为34

当我们输入1[Tab]234时,变量a的值为1,变量b值为234

当我们输入12回车时,变量a的值为12,变量b值为空

当我们输入123^C时,read命令被终止了,所以变量a的值没有变化,仍为12,变量b值没有变化,仍为空

2.6 -N 指定输入字符个数

例 读取5个字符,分别保存到变量a和b

purpleEndurer @ bash ~ $ read -N 5 a b
12      34purpleEndurer @ bash ~ $ echo a=$a b=$b
a=12 34 b=
purpleEndurer @ bash ~ $ read -N 5 a b
12 34purpleEndurer @ bash ~ $ echo a=$a b=$b
a=12 34 b=
purpleEndurer @ bash ~ $ read -d '#' -N 5 a b
12#34purpleEndurer @ bash ~ $ echo a=$a b=$b
a=12#34 b=
purpleEndurer @ bash ~ $ 

 

 当我们输入12[Tab]34时,变量a的值为12    34,变量b值为空

当我们输入12空格34时,变量a的值为12 34,变量b值为空

即使我们用-t '#' 选项指定#作为结束符,输入12#34,结果变量a的值为12#34,变量b值为空 

  • 看来使用-N选项后,空格或[Tab]不再作为字符串值的分隔符,-t选项也不起作用,这样只能将读取值存到第1个变量中了。

2.7 -s不回显来自终端的输入

例:提示用户输入密码,输入时不回显,输入完成后再显示用户输入的密码。

purpleEndurer @ bash ~ $ read -s -p "Enter your password:" p
Enter your password:purpleEndurer @ bash ~ $ echo Your password is $p
Your password is abcd
purpleEndurer @ bash ~ $ 

当用户输入密码abcd时并不回显,按回车键后,才显示用户输入的密码是abcd。

2.8 -e使用命令补全功能

PurpleEndurer @ bash ~ $ ls
Code
PurpleEndurer @ bash ~ $ read -e a
Code/
PurpleEndurer @ bash ~ $ echo $a
Code/
PurpleEndurer @ bash ~ $ read -e a
cde
PurpleEndurer @ bash ~ $ echo $a
cde
PurpleEndurer @ bash ~ $ 

我们先用ls命令查看当前目录内容,存在一个名Code的文件或文件夹

然后我们用命令 read -e a 来读取输入存到变量a

在我们输入大写字符C后按Tab键启用命令补全功能,输入行的内容就变为Code/,按下回车键。

再用echo $a 查看变量a的值为Code/

在我们输入大写字符C后按Tab键启用命令补全功能,输入行的内容就变为Code/,我们用删除键Backspace删除Code/,输入cde回车,再用echo $a 查看变量a的值为cde

2.9 -r 允许输入的值中包含的反斜杠\也作为值输出

purpleEndurer @ bash ~/Code $ read a
//\c
purpleEndurer @ bash ~/Code $ echo $a
//c
purpleEndurer @ bash ~/Code $ read -r a
//\c
purpleEndurer @ bash ~/Code $ echo $a
//\c
purpleEndurer @ bash ~/Code $ 

对于命令 read a,输入   //\c,存储到变量a的值为 //C,不包含反斜杠\。

对于命令 rread -r a,输入   //\c,存储到变量a的值为 //\C,包含反斜杠\。

2.10 -a 读取数组值

数组是最常用的一种数据结构,在之前的

Linux shell编程学习笔记15:定义数组、获取数组元素值和长度、数组拼接或合并_linux获取数组长度-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/Purpleendurer/article/details/134009982

Linux shell编程学习笔记16:bash中的关联数组-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/Purpleendurer/article/details/134053506中我们学习了Lininux Shell编程中的数组的定义和赋值的方法,其中对数组元素的赋值方法 ,我们主要介绍了在定义数组时同时进行初始化和定义数组后用赋值语句来赋值两种方法。

现在我们也可以用read命令来将用户输入的值存储到数组

例:从键盘读取输入存入数组a

purpleEndurer @ bash ~/Code $ read -a a
1 2 3
purpleEndurer @ bash ~/Code $ echo ${a[*]}
1 2 3
purpleEndurer @ bash ~/Code $ echo ${a[0]}
1
purpleEndurer @ bash ~/Code $ 

i当我们输入 1 2 3,那么 a[0]=1,a[1]=2,a[2]=3

可惜的是,read命令不能将用户输入存储到关联数组

purpleEndurer @ bash ~/Code $ declare -A A
purpleEndurer @ bash ~/Code $ read -a A
a b c
bash: read: A: cannot convert associative to indexed array
purpleEndurer @ bash ~/Code $ 

我们先用命令 声明一个关联数组A

然后用命令 来读取用户输入存储到关联数组A,但是出错了:bash: read: A: cannot convert associative to indexed array

2.11 -u指定文件说明符

例:将文件a.txt和b.txt的内容逐行拼接显示。

purpleEndurer @ bash ~ $ cp /dev/stdin a.txt
111
222
333
444
purpleEndurer @ bash ~ $ cp /dev/stdin b.txt
aaa
bbb
ccc
ddd
eee
purpleEndurer @ bash ~ $ while read -u3 i && read -u4 j;do echo $i $j; done 3<a.txt 4<b.txt
111 aaa
222 bbb
333 ccc
444 ddd
purpleEndurer @ bash ~ $ 

如果我们希望在每一行前显示行号,那么我们可以增加一个变量n用来记录当前行数:

purpleEndurer @ bash ~ $ n=1;while read -u3 i && read -u4 j;do echo Line $n:  $i $j;n=$[ $n + 1 ];  done 3<a.txt 4<b.txt
Line 1: 111 aaa
Line 2: 222 bbb
Line 3: 333 ccc
Line 4: 444 ddd
purpleEndurer @ bash ~ $ 

2.12 -i 使用初始值

例 提示用户输入用户名 存储到变量a中,用户名初始值为 Anonymous

PurpleEndurer @ bash ~ $ read -p 'Enter your name:' -i 'Anonymous' a 
Enter your name:
PurpleEndurer @ bash ~ $ echo $a

PurpleEndurer @ bash ~ $ read -p 'Enter your name:' -i 'Anonymous' -e a 
Enter your name:Anonymous
PurpleEndurer @ bash ~ $ echo $a
Anonymous
PurpleEndurer @ bash ~ $ read -p 'Enter your name:' -i 'Anonymous' -e a 
Enter your name:abc
PurpleEndurer @ bash ~ $ echo $a
abc
PurpleEndurer @ bash ~ $ 

在执行 命令  read -p 'Enter your name:' -i 'Anonymous' a  时,虽然我们使用 -i  'Anonymous'选项,但执行时并没有显示初始值 Anonymous,我们直接回车,变量a的值为空

在执行 命令  read -p 'Enter your name:' -i 'Anonymous' -e a   时,我们在上面的命令中增加了 -e选项,在执行时就显示出初始值 Anonymous,我们直接回车,变量a的值为就为 Anonymous

在执行 命令  read -p 'Enter your name:' -i 'Anonymous' -e a   时,我们在上面的命令中增加了 -e选项,在执行时就显示出初始值 Anonymous,我们按删除键Backspace删除 Anonymous,输入abc回车,变量a的值为abc

相关文章:

Linux shell编程学习笔记36:read命令

*更新日志 *2023-12-18 1.根据[美] 威廉肖特斯 &#xff08;Willian shotts&#xff09;所著《Linux命令行大全&#xff08;第2版&#xff09;》 更新了-e、-i、-r选项的说明 2.更新了 2.8 的实例&#xff0c;增加了gif动图 3.补充了-i的应用实例 2.1…...

Python表达式

表达式 本章将解释 Python 中组成表达式的各种元素的的含义。 语法注释: 在本章和后续章节中&#xff0c;会使用扩展 BNF 标注来描述语法而不是词法分析。 当&#xff08;某种替代的&#xff09;语法规则具有如下形式 name :: othername并且没有给出语义&#xff0c;则这种…...

风速预测(六)基于Pytorch的EMD-CNN-GRU并行模型

目录 前言 1 风速数据EMD分解与可视化 1.1 导入数据 1.2 EMD分解 2 数据集制作与预处理 2.1 先划分数据集&#xff0c;按照8&#xff1a;2划分训练集和测试集 2.2 设置滑动窗口大小为96&#xff0c;制作数据集 3 基于Pytorch的EMD-CNN-GRU并行模型预测 3.1 数据加载&a…...

【Stm32-F407】全速DAP仿真器下载程序

文章内容如下: 1) 全速DAP仿真器简介2) 全速DAP仿真器下载程序流程 1) 全速DAP仿真器简介 1&#xff09;全速DAP仿真器简介 DAP全称 Data Acquisition Processor&#xff0c;是一种用于数据采集和实时控制的设备。本文使用的全速DAP仿真器遵循ARM公司的CMSIS-DAP标准&#xff…...

ArcGIS Pro SDK导出的几何XML和Json

本博主会持续更新关于ArcGIS Pro SDK的相关内容&#xff0c;请读者关注一下 圆 XML <PolygonN xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance" xmlns:xs"http://www.w3.org/2001/XMLSchema" xmlns:typens"http://www.esri.com/schemas/…...

随笔记录-springboot_LoggingApplicationListener+LogbackLoggingSystem

环境&#xff1a;springboot-2.3.1 加载日志监听器初始化日志框架 SpringApplication#prepareEnvironment SpringApplicationRunListeners#environmentPrepared EventPublishingRunListener#environmentPrepared SimpleApplicationEventMulticaster#multicastEvent(Applicati…...

超级计算机与天气预报:精准预测的科技革命

超级计算机与天气预报&#xff1a;精准预测的科技革命 一、引言 随着科技的飞速发展&#xff0c;超级计算机已经成为现代社会不可或缺的一部分。它们在科研、工业、军事等领域发挥着重要作用&#xff0c;其中天气预报是一个颇具代表性的应用领域。本文将探讨超级计算机在天气…...

【uniapp小程序-分享】

//分享到聊天onShareAppMessage() {let shareMessage {title: this.liveInfo.wx_title,path: /subPages/livePages/liveCourse/live_course_info?courseid this.courseid,imageUrl: this.liveInfo.wx_thumb};let shearMsg uni.getStorageSync(shearImg this.courseid);if (…...

思幻二次元风格的工作室个人引导页源码

思幻工作室个人引导页源码已经完成开发&#xff01;该源码支持三端自适应&#xff0c;并且具备赞助功能。我们选择了当前点赞量最高的配色方案&#xff0c;打造了一个独特的二次元风格引导页。经过在美国服务器上进行的测试&#xff0c;效果令人满意&#xff0c;网页加载速度达…...

Rsync+notify文件实时同步工具

rsync ( Remote sync&#xff0c;远程同步) 是一个开源的快速备份工具&#xff0c;可以在不同主机之间镜像同步整个目录树&#xff0c;支持增量备份&#xff0c;并保持链接和权限&#xff0c;且采用优化的同步算法&#xff0c;传输前执行压缩&#xff0c;因此非常适用于异地备…...

小信砍柴的题解

目录 原题描述&#xff1a; 时间&#xff1a;1s 空间&#xff1a;256M 题目描述&#xff1a; 输入格式&#xff1a; 输出格式&#xff1a; 样例1输入&#xff1a; 题目大意&#xff1a; 主要思路&#xff1a; 注意事项&#xff1a; 总代码&#xff1a; 原题描述&#…...

华为OD机试 - 跳格子3(Java JS Python C)

题目描述 小明和朋友们一起玩跳格子游戏, 每个格子上有特定的分数 score = [1, -1, -6, 7, -17, 7], 从起点score[0]开始,每次最大的步长为k,请你返回小明跳到终点 score[n-1] 时,能得到的最大得分。 输入描述 第一行输入总的格子数量 n 第二行输入每个格子的分数 sc…...

每天五分钟计算机视觉:谷歌的Inception模块的计算成本的问题

计算成本 Inception 层还有一个问题,就是计算成本的问题,我们来看一下55 过滤器在该模块中的计算成本。 原始图片为28*28*192经过32个5*5的过滤操作,它的计算成本为: 我们输出28*28*32个数字,对于输出的每个数字来说,你都需要执行 55192 (5*5为卷积核的大小,192为通道…...

最新AI创作系统ChatGPT系统源码+DALL-E3文生图+支持AI绘画+GPT语音对话功能

一、AI创作系统 SparkAi创作系统是基于ChatGPT进行开发的Ai智能问答系统和Midjourney绘画系统&#xff0c;支持OpenAI-GPT全模型国内AI全模型。本期针对源码系统整体测试下来非常完美&#xff0c;可以说SparkAi是目前国内一款的ChatGPT对接OpenAI软件系统。那么如何搭建部署AI…...

78-C语言-完数的判断,以及输出其因子

简介&#xff1a;一个数如果恰好等于它的因子之和&#xff0c;这个数就称为完数&#xff0c;C语言编程找出1000之内的所有完数&#xff0c;并输出其因子。因子可以整除该数字的数&#xff0c; 如6的因子&#xff1a;1 2 3&#xff0c;6%10 6%20 6%30 解释全在注…...

C# 使用FluentHttpClient请求WebApi

写在前面 FluentHttpClient 是一个REST API 异步调用 HTTP 客户端&#xff0c;调用过程非常便捷&#xff0c;采用流式编程&#xff0c;可以将所有请求所需的参数一次性发送&#xff0c;并直接获取序列化后的结果。 老规矩从NuGet上安装该类库&#xff1a; 这边一定要认准是 P…...

AXure交互及案列

AXure交互及案列 1.交互样式简介2.axure交互事件简介3.axure交互动作简介4.axure情形简介2.完成案列1.登录案列2.省市联动案列3.左侧联动 1.交互样式简介 Axure是一种强大的原型设计工具&#xff0c;它允许用户创建高保真的交互式原型&#xff0c;用于演示和测试Web和移动应用…...

美颜SDK技术对比,深入了解视频美颜SDK的工作机制

如何在实时视频中呈现更加自然、美丽的画面&#xff0c;而这正是美颜SDK技术发挥作用的领域之一。本文将对几种主流视频美颜SDK进行深入比较&#xff0c;以揭示它们的工作机制及各自的优劣之处。 随着科技的不断进步&#xff0c;美颜技术已经从简单的图片处理发展到了视频领域…...

OkHttp ,使用 HttpUrl.Builder 来添加查询参数并添加到请求对象

在使用 OkHttp 中&#xff0c;你可以使用 HttpUrl.Builder 来添加查询参数并将其添加到请求对象中。下面是一个示例代码&#xff1a; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response;public class Main {public stat…...

图片速览 PoseGPT:基于量化的 3D 人体运动生成和预测(VQVAE)

papercodehttps://arxiv.org/pdf/2210.10542.pdfhttps://europe.naverlabs.com/research/computer-vision/posegpt/ 方法 将动作压缩到离散空间。使用GPT类的模型预测未来动作的离散索引。使用解码器解码动作得到输出。 效果 提出的方法在HumanAct12&#xff08;一个标准但小规…...

基于距离变化能量开销动态调整的WSN低功耗拓扑控制开销算法matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.算法仿真参数 5.算法理论概述 6.参考文献 7.完整程序 1.程序功能描述 通过动态调整节点通信的能量开销&#xff0c;平衡网络负载&#xff0c;延长WSN生命周期。具体通过建立基于距离的能量消耗模型&am…...

从零实现富文本编辑器#5-编辑器选区模型的状态结构表达

先前我们总结了浏览器选区模型的交互策略&#xff0c;并且实现了基本的选区操作&#xff0c;还调研了自绘选区的实现。那么相对的&#xff0c;我们还需要设计编辑器的选区表达&#xff0c;也可以称为模型选区。编辑器中应用变更时的操作范围&#xff0c;就是以模型选区为基准来…...

Docker 运行 Kafka 带 SASL 认证教程

Docker 运行 Kafka 带 SASL 认证教程 Docker 运行 Kafka 带 SASL 认证教程一、说明二、环境准备三、编写 Docker Compose 和 jaas文件docker-compose.yml代码说明&#xff1a;server_jaas.conf 四、启动服务五、验证服务六、连接kafka服务七、总结 Docker 运行 Kafka 带 SASL 认…...

在web-view 加载的本地及远程HTML中调用uniapp的API及网页和vue页面是如何通讯的?

uni-app 中 Web-view 与 Vue 页面的通讯机制详解 一、Web-view 简介 Web-view 是 uni-app 提供的一个重要组件&#xff0c;用于在原生应用中加载 HTML 页面&#xff1a; 支持加载本地 HTML 文件支持加载远程 HTML 页面实现 Web 与原生的双向通讯可用于嵌入第三方网页或 H5 应…...

rnn判断string中第一次出现a的下标

# coding:utf8 import torch import torch.nn as nn import numpy as np import random import json""" 基于pytorch的网络编写 实现一个RNN网络完成多分类任务 判断字符 a 第一次出现在字符串中的位置 """class TorchModel(nn.Module):def __in…...

基于Java+MySQL实现(GUI)客户管理系统

客户资料管理系统的设计与实现 第一章 需求分析 1.1 需求总体介绍 本项目为了方便维护客户信息为了方便维护客户信息&#xff0c;对客户进行统一管理&#xff0c;可以把所有客户信息录入系统&#xff0c;进行维护和统计功能。可通过文件的方式保存相关录入数据&#xff0c;对…...

【Linux系统】Linux环境变量:系统配置的隐形指挥官

。# Linux系列 文章目录 前言一、环境变量的概念二、常见的环境变量三、环境变量特点及其相关指令3.1 环境变量的全局性3.2、环境变量的生命周期 四、环境变量的组织方式五、C语言对环境变量的操作5.1 设置环境变量&#xff1a;setenv5.2 删除环境变量:unsetenv5.3 遍历所有环境…...

【LeetCode】算法详解#6 ---除自身以外数组的乘积

1.题目介绍 给定一个整数数组 nums&#xff0c;返回 数组 answer &#xff0c;其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法&#xff0c;且在 O…...

图解JavaScript原型:原型链及其分析 | JavaScript图解

​​ 忽略该图的细节&#xff08;如内存地址值没有用二进制&#xff09; 以下是对该图进一步的理解和总结 1. JS 对象概念的辨析 对象是什么&#xff1a;保存在堆中一块区域&#xff0c;同时在栈中有一块区域保存其在堆中的地址&#xff08;也就是我们通常说的该变量指向谁&…...

基于江科大stm32屏幕驱动,实现OLED多级菜单(动画效果),结构体链表实现(独创源码)

引言 在嵌入式系统中&#xff0c;用户界面的设计往往直接影响到用户体验。本文将以STM32微控制器和OLED显示屏为例&#xff0c;介绍如何实现一个多级菜单系统。该系统支持用户通过按键导航菜单&#xff0c;执行相应操作&#xff0c;并提供平滑的滚动动画效果。 本文设计了一个…...