[linux] bash 计算 i+1

Posted 心心喵

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[linux] bash 计算 i+1相关的知识,希望对你有一定的参考价值。

SHELL中的双括号
2011-06-30 14:58
在bash中计算i=i+1有三种办法:
1.i=$(($i+1))
2.i=`expr $i + 1`
3.let “i=i+1″

其中第一种和第二种是可以在sh里面使用的,第三种只能在bash里使用,还是第一种最简单,通用。

双括号还有妙用
for ((i=1;i<=num;i++))

shell里面是不允许if [ $a != 1 || $b = 2 ]出现的,要用
if [ $a != 1 ] || [ $b = 2 ]]

用双括号可以解决
if [[ $a != 1 || $b = 2 ]]

if [ "$a" -lt "$b" ]也可以改成双括号的形式
((“$a” < “$b”))

计算机基础——Linux的bash.shell,help,man命令

Linux指令和对应的英文全称,Linux单横杠和双横杠的区别_iaiti的博客-CSDN博客_linux 命令 横杠https://blog.csdn.net/iaiti/article/details/120024765?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165465329616781432967630%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165465329616781432967630&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-120024765-null-null.article_score_rank_blog&utm_term=%E6%A8%AA%E6%9D%A0&spm=1018.2226.3001.4450

Linux指令和对应的英文全称,Linux单横杠和双横杠的区别,在这篇中写道的指令全称,如果忘记指令作用时,可以使用帮助命令help。
那其实help是什么。

系统敲入help指令后有如下输出

GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
These shell commands are defined internally.  Type `help' to see this list.
Type `help name' to find out more about the function `name'.

help是bash命令,那bash是什么,bash是 Linux与Mac OS X v10.4都将它作为默认shell—— bash,命令处理器,运行在文本窗口中。那用惯的windows的shell就是cmd进去的命令行了。
那shell是什么
shell是壳,传统意义上的shell是命令行shell,是与os的通讯方式。好像个传话筒,你叫操作系统做什么通过他。
那现在又会思考,那操作系统是什么,一层层嵌套的一个问题。我们去找下 linux的架构图。
其实shell也是整个os的一部分。通过shell经由内核跟底层的硬件做交互。那底层通了之后再递归回去原始的问题。


shell作为传话筒,告诉内核和硬件之间的交互然后得出想要的结果。Korn shell,Bourne shell,C shell,POSIX shell
Bash是Bourne shell的后继兼容版本与开放源代码版本

内核结构图

help是bash命令,其实在其他一些命令行shell中也有用,只是不是linux的而已,比如windows的dos窗口cmd.exe,python

使用内部 bash 结构来存储和检索有关 bash 命令的信息。


与--help不同的是,--help是对应指令自带的参数,Linux单横杠和双横杠的区别的设计就是单横杠可以拼接多个参数,--用于区分单词

除了help外,我们查看命令的说明还会用到man命令

同样输入man会得到
What manual page do you want?
Defines  what  to display on stdout after a completed and successful operation. The format is a string that may contain plain text mixed with any number of variables. The
              string can be specified as "string", to get read from a particular file you specify it "@filename" and to tell curl to read the format from stdin you write "@-".


man指令的解释是
A man page (short for manual page) is a form of software documentation usually found on a Unix or Unix-like operating system. 

用的是groff编写,groff,是经典的文本处理系统 troff 的一个现代实现。troff 是 “排版工快印(typesetter roff)” 的简称
The default format of man pages is troff

与help的区别是,是查看内部的命令帮助信息,外部指令信息需要使用man或者info查看。

以上是关于[linux] bash 计算 i+1的主要内容,如果未能解决你的问题,请参考以下文章

[linux] bash 计算 i+1

在服务器中连接docker,执行容器里面的命令

Linux下的计算命令整理

shell 脚本常用写法

Bash 中的 eval 命令及其典型用途

Ubuntu切换默认sh为bash或者dash