?? arith-ops.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 + -