vartrace.sh

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

SH
32
字号
#!/bin/bashtrap 'echo "VARIABLE-TRACE> \$variable = \"$variable\""' DEBUG# Echoes the value of $variable after every command.variable=29echo "Just initialized \"\$variable\" to $variable."let "variable *= 3"echo "Just multiplied \"\$variable\" by 3."exit $?#  The "trap 'command1 . . . command2 . . .' DEBUG" construct is#+ more appropriate in the context of a complex script,#+ where placing multiple "echo $variable" statements might be#+ clumsy and time-consuming.# Thanks, Stephane Chazelas for the pointer.Output of script:VARIABLE-TRACE> $variable = ""VARIABLE-TRACE> $variable = "29"Just initialized "$variable" to 29.VARIABLE-TRACE> $variable = "29"VARIABLE-TRACE> $variable = "87"Just multiplied "$variable" by 3.VARIABLE-TRACE> $variable = "87"

⌨️ 快捷键说明

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