arith-tests.sh

来自「Shall高级编程」· Shell 代码 · 共 38 行

SH
38
字号
#!/bin/bash# Arithmetic tests.# The (( ... )) construct evaluates and tests numerical expressions.# Exit status opposite from [ ... ] construct!(( 0 ))echo "Exit status of \"(( 0 ))\" is $?."         # 1(( 1 ))echo "Exit status of \"(( 1 ))\" is $?."         # 0(( 5 > 4 ))                                      # trueecho "Exit status of \"(( 5 > 4 ))\" is $?."     # 0(( 5 > 9 ))                                      # falseecho "Exit status of \"(( 5 > 9 ))\" is $?."     # 1(( 5 - 5 ))                                      # 0echo "Exit status of \"(( 5 - 5 ))\" is $?."     # 1(( 5 / 4 ))                                      # Division o.k.echo "Exit status of \"(( 5 / 4 ))\" is $?."     # 0(( 1 / 2 ))                                      # Division result < 1.echo "Exit status of \"(( 1 / 2 ))\" is $?."     # Rounded off to 0.                                                 # 1(( 1 / 0 )) 2>/dev/null                          # Illegal division by 0.#           ^^^^^^^^^^^echo "Exit status of \"(( 1 / 0 ))\" is $?."     # 1# What effect does the "2>/dev/null" have?# What would happen if it were removed?# Try removing it, then rerunning the script.exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?