⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arith-ops.sh

📁 一本完整的描述Unix Shell 编程的工具书的所有范例
💻 SH
字号:
#!/bin/bash# Counting to 11 in 10 different ways.n=1; echo -n "$n "let "n = $n + 1"   # let "n = n + 1"  also works.echo -n "$n ": $((n = $n + 1))#  ":" necessary because otherwise Bash attempts#+ to interpret "$((n = $n + 1))" as a command.echo -n "$n "(( n = n + 1 ))#  A simpler alternative to the method above.#  Thanks, David Lombard, for pointing this out.echo -n "$n "n=$(($n + 1))echo -n "$n ": $[ n = $n + 1 ]#  ":" necessary because otherwise Bash attempts#+ to interpret "$[ n = $n + 1 ]" as a command.#  Works even if "n" was initialized as a string.echo -n "$n "n=$[ $n + 1 ]#  Works even if "n" was initialized as a string.#* Avoid this type of construct, since it is obsolete and nonportable.#  Thanks, Stephane Chazelas.echo -n "$n "# Now for C-style increment operators.# Thanks, Frank Wang, for pointing this out.let "n++"          # let "++n"  also works.echo -n "$n "(( n++ ))          # (( ++n )  also works.echo -n "$n ": $(( n++ ))       # : $(( ++n )) also works.echo -n "$n ": $[ n++ ]         # : $[ ++n ]] also worksecho -n "$n "echoexit 0

⌨️ 快捷键说明

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