无锡网络建站网站做微信链接
- 作者: 五速梦信息网
- 时间: 2026年04月20日 07:16
当前位置: 首页 > news >正文
无锡网络建站,网站做微信链接,小组用jsp做的网站论文,个网站做淘宝客推广可以吗0 前言 在使用 for 循环语句时#xff0c;我们经常使用到序列。比如#xff1a; for i in 1 2 3 4 5 6 7 8 9 10; do echo \(i * 2 \)(expr \(i \* 2); done 其中的 1 2 3 4 5 6 7 8 9 10;就是一个整数序列 。 为了方便我们使用数字序列#xff0c;Linux提供了… 0 前言 在使用 for 循环语句时我们经常使用到序列。比如 for i in 1 2 3 4 5 6 7 8 9 10; do echo \)i * 2 \((expr \)i * 2); done 其中的 1 2 3 4 5 6 7 8 9 10;就是一个整数序列 。 为了方便我们使用数字序列Linux提供了seq命令这个命令是取自单词sequence的前3个字母。比如 for i in \((seq 1 10) ; do 更多信息请回顾 Linux shell编程学习笔记17for循环语句-CSDN博客https://blog.csdn.net/Purpleendurer/article/details/134102934?spm1001.2014.3001.5501 其实seq命令的用途和使用环境很广阔。现在我们就来探究一下。 1 seq命令的格式、功能 我们可以使用命令 seq --help 来查看seq命令的帮助信息 purpleEndurer bash ~ \) seq –help Usage: seq [OPTION]… LAST or: seq [OPTION]… FIRST LAST or: seq [OPTION]… FIRST INCREMENT LAST Print numbers from FIRST to LAST, in steps of INCREMENT. Mandatory arguments to long options are mandatory for short options too. -f, –formatFORMAT use printf style floating-point FORMAT -s, –separatorSTRING use STRING to separate numbers (default: \n) -w, –equal-width equalize width by padding with leading zeroes –help display this help and exit –version output version information and exit If FIRST or INCREMENT is omitted, it defaults to 1. That is, an omitted INCREMENT defaults to 1 even when LAST is smaller than FIRST. The sequence of numbers ends when the sum of the current number and INCREMENT would become greater than LAST. FIRST, INCREMENT, and LAST are interpreted as floating point values. INCREMENT is usually positive if FIRST is smaller than LAST, and INCREMENT is usually negative if FIRST is greater than LAST. FORMAT must be suitable for printing one argument of type double; it defaults to %.PRECf if FIRST, INCREMENT, and LAST are all fixed point decimal numbers with maximum precision PREC, and to %g otherwise. GNU coreutils online help: http://www.gnu.org/software/coreutils/ Report seq translation bugs to http://translationproject.org/team/ For complete documentation, run: info coreutils seq invocation purpleEndurer bash ~ \( 1.1 seq 命令的格式 seq [选项]... [序列起始数] [步长] 序列结尾数 1.1.1 参数 序列起始数可以是0、正整数 或 负整数未指定时默认为1序列结尾数可以是0、正整数 或 负整数步长 可以是 正整数 或 负整数未指定时默认为1 1.1.2 选项 选项说明备注 -f格式字符串 -f 格式字符串 -f格式字符串 --formatFORMAT --format FORMAT 使用printf命令中的格式字符串来格式化输出默认为%g 数字位数不足部分默认是空格 不能与 -w 或 --equal-width 同时使用 format -s分隔字符串 -s 分隔字符串 -s分隔字符串 --separator 分隔字符串 --separator分隔字符串 使用指定的字符串作为数字间的分隔符(默认字符串是\n) 指定作分隔符的字符串可以是空字符串也可以1位字符或者多位字符 separator -w --equal-width 通过用前导零填充来均衡宽度 不能与 -f 或 --format 同时使用 width--help显示帮助信息并退出help--version输出版本信息并退出version 1.2 seq命令的功能 生成以超始数开始逐一加上步长直到结尾数的数列并以指定的格式输出。 2 seq 命令用法实例 2.1 seq不带参数会报错返加值为1 purpleEndurer bash ~ \) seq seq: missing operand Try seq –help for more information. purpleEndurer bash ~ \( echo \)? 1 purpleEndurer bash ~ \( 2.2 生成递增序列 例 2.2 生成从1开始步长为1到10为止的序列 完整的命令是seq 1 1 10 purpleEndurer bash ~ \) seq 1 1 10 1 2 3 4 5 6 7 8 9 10 purpleEndurer bash ~ \( 由于seq的 步长未指定时默认为1所以我们可以将命令中代表步长的第二个1省略从而简写为seq 1 10 purpleEndurer bash ~ \) seq 1 10 1 2 3 4 5 6 7 8 9 10 purpleEndurer bash ~ \( 由于seq的 序列起始数未指定时默认为1所以我们可以将命令中的第一个1省略进一步简写为seq 10 purpleEndurer bash ~ \) seq 10 1 2 3 4 5 6 7 8 9 10 purpleEndurer bash ~ \( 2.3 生成递减序列 例 2.3 生成从10开始步长为-2到-10为止的序列 完整的命令是seq 10 -2 -10 purpleEndurer bash ~ \) seq 10 -2 -10 10 8 6 4 2 0 -2 -4 -6 -8 -10 purpleEndurer bash ~ \( 2.4 指定格式字符串 2.4.1 系统默认为%g purpleEndurer bash ~ \) seq -f %g 10 -2 -10 10 8 6 4 2 0 -2 -4 -6 -8 -10 purpleEndurer bash ~ \( 可以看到当我们指定格式字符串为%g时显示结果与不指定是一样的。 2.4.2 自定义格式字符串 例如我们指定以开头宽度为5来显示 以下命令均可以实现 seq -f%5g 10 -2 -10seq -f%5g 10 -2 -10seq -f %5g 10 -2 -10seq --format%5g 10 -2 -10seq --format %5g 10 -2 -10 purpleEndurer bash ~ \) seq -f %5g 10 -2 -10 10 8 6 4 2 0 -2 -4 -6 -8 -10 purpleEndurer bash ~ \( seq -f %5g 10 -2 -10 10 8 6 4 2 0 -2 -4 -6 -8 -10 purpleEndurer bash ~ \) seq –format%5g 10 -2 -10 10 8 6 4 2 0 -2 -4 -6 -8 -10 purpleEndurer bash ~ \( seq --format %5g 10 -2 -10 10 8 6 4 2 0 -2 -4 -6 -8 -10 purpleEndurer bash ~ \) 可以看到seq命令默认是用空格来补位如果我们想用0来补位可以使用命令 seq -f%05g 10 -2 -10 purpleEndurer bash ~ \( seq -f%05g 10 -2 -10 00010 00008 00006 00004 00002 00000 -0002 -0004 -0006 -0008 -0010 purpleEndurer bash ~ \) 2.5 使用-w选项平衡宽度不足时用0填充 purpleEndurer bash ~ \( seq -w 10 -2 -10 010 008 006 004 002 000 -02 -04 -06 -08 -10 purpleEndurer bash ~ \) 虽然 -w 和 -f%5g都是以0来填充空位的但是对比二者的显示结果可以发现二者存在一定的区别 -w是以生成的序列中位数最长的位数包括负号-为最大位数 例如在命令 seq -w 10 -2 -10 中生成的序列中 位数最长的是-10即3位数所以生成序列均为3位数。 -f选项可以直接指定位数 例如在命令 seq -f%05g 10 -2 -10 中生成的序列中 位数最长的是-10即3位数但由于我们指定宽度为5所以显示的序列均为5位数。 2.6 指定序列分隔符 seq命令默认序列分隔符为换行符\n我们可能使用-s或–separator指定其它分隔符指定的分隔符字符串可以是空字符串也可以1位字符或者多位字符。 例如生成从10开始步长为-2到-10为止的序列以两个冒号作为分隔符 使用命令都可以实现 seq -s :: 10 -2 -10seq -s:: 10 -2 -10seq -s:: 10 -2 -10seq –separator :: 10 -2 -10seq –separator:: 10 -2 -10 purpleEndurer bash ~ \( seq -s :: 10 -2 -10 10::8::6::4::2::0::-2::-4::-6::-8::-10 purpleEndurer bash ~ \) seq –separator :: 10 -2 -10 10::8::6::4::2::0::-2::-4::-6::-8::-10 purpleEndurer bash ~ \( seq --separator:: 10 -2 -10 10::8::6::4::2::0::-2::-4::-6::-8::-10 purpleEndurer bash ~ \) seq -s:: 10 -2 -10 10::8::6::4::2::0::-2::-4::-6::-8::-10 purpleEndurer bash ~ \( 我们也可以使用空字符串作为分隔符 purpleEndurer bash ~ \) seq –separator 10 -2 -10 1086420-2-4-6-8-10 purpleEndurer bash ~ \( 3 seq 命令的类型 is hashed 在 Linux shell编程学习笔记33type 命令-CSDN博客https://blog.csdn.net/Purpleendurer/article/details/134804451?spm1001.2014.3001.5501中我们知道type命令 可以显示指定命令的信息判断给出的指令是内部命令、外部命令文件、别名、函数、保留字 或者 不存在找不到。 但对于seq命令type命令显示的是 “seq is hashed (/usr/bin/seq)” purpleEndurer bash ~ \) type seq seq is hashed (/usr/bin/seq) purpleEndurer bash ~ \( 这是什么意思呢 bing了一下在bash - What does is hashed mean when using the type command? - Unix Linux Stack Exchangehttps://unix.stackexchange.com/questions/251731/what-does-is-hashed-mean-when-using-the-type-command 给出的解释是 What that means is that after finding the location of a command the first time (or when hash is invoked), its location is remembered (hashed). 翻译过来就是 这意味着在第一次找到命令的位置或调用哈希时后会记住它的位置散列。 我们可以通过下面的命令序列来理解 purpleEndurer bash ~ \) type seq seq is /usr/bin/seq purpleEndurer bash ~ \( seq seq: missing operand Try seq --help for more information. purpleEndurer bash ~ \) type seq seq is hashed (/usr/bin/seq) purpleEndurer bash ~ $ 当我们登录系统后还没有执行seq命令时使用type seq命令命令显示的信息是seq is /usr/bin/seq 说明它是个外部命令。 当我们执行seq命令后再使用type seq命令命令显示的信息是seq is hashed (/usr/bin/seq) 即此时系统已记住了seq命令的位置。
相关文章
-
无锡市建设培训中心网站浙江省专业网站制作网站建设
无锡市建设培训中心网站浙江省专业网站制作网站建设
- 技术栈
- 2026年04月20日
-
无锡企业网站排名汽车网有哪些网站大全
无锡企业网站排名汽车网有哪些网站大全
- 技术栈
- 2026年04月20日
-
无锡企业如何建网站潍坊专业网站建设
无锡企业如何建网站潍坊专业网站建设
- 技术栈
- 2026年04月20日
-
无锡网站的优化建设网络平台的技术服务合同交印花税吗
无锡网站的优化建设网络平台的技术服务合同交印花税吗
- 技术栈
- 2026年04月20日
-
无锡网站定制公司网站建设海报设计
无锡网站定制公司网站建设海报设计
- 技术栈
- 2026年04月20日
-
无锡网站关键词优化软件咨询什么网站可以做项目
无锡网站关键词优化软件咨询什么网站可以做项目
- 技术栈
- 2026年04月20日
