The expr Command test And The test Command

在这节课中,你将学习:
expr命令 – The expr Command
test命令 – The test Command
使用shell脚本中的编程结构 – Use programming constructs in shell scripts

管道用于将一个命令的标准输出作为标准输入发送到另一个命令。Pipes are used to send the standard output of one command as the standard input to another.
在单个命令行中使用多个命令的另一种方法是通过命令替换。Another way of using more than one command in a single command line is through command substitution.
您可以使用以下命令将命令的输出存储在变量中:You can use the following commands to store the output of a command in a variable:
The expr command
The test command

大多数shell不支持数值变量。
Most shells do not support numeric variables.
使用expr命令计算算术表达式
The use of the expr command evaluates arithmetic expressions.
expr命令的输出被发送到标准输出。
The output of the expr command is sent to the standard output.
下面的例子演示了expr命令的用法:
The following example demonstrates the usage of expr command:
$expr 4 + 5
命令支持的操作符是+、-、*、/和
The operators supported by the expr command are +, -,/, and %.
如果需要将expr命令的输出存储在变量中,则可以使用命令替换。
If you require the output of the expr command to be stored in a variable instead, you can use command substitution.

test命令对表达式求值,并返回true(0)或false(1)。
The test command evaluates an expression and either returns a true (0) or a false (1).
还可以用[(方括号)替换test关键字。
The test keyword can also be replaced with 0] (square brackets).
test命令可用于检查变量的值
The test command can be used to check the values of variables.
下面的例子演示了如何使用test和[]命令来使用空间:
The following example demonstrates the usage of space with the test and [] commands:
test $user name =“Roge. r”
[ $user name = “Roger”]
还可以在一个测试命令中测试多个条件
Multiple conditions can also be tested in one test

Linux shell提供了用于循环和决策的构造,可以在shell脚本中使用这些构造。
The Linux shell offers constructs for looping and decision-making, which can be used in shell scripts.
一些构念是:
Some of the constructs are:
The i f construct
The case . . . esac construct
The whi le construct
The until construct
The for construct
exit和test命令可以与if结构一起使用。
The exit and test commands can be used with the if construct.
break和continue命令可以与while构造一起使用。
The break and continue commands can be used with the while construct.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值