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

📄 subshell.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash# subshell.shechoecho "We are outside the subshell."echo "Subshell level OUTSIDE subshell = $BASH_SUBSHELL"# Bash, version 3, adds the new         $BASH_SUBSHELL variable.echo; echoouter_variable=Outerglobal_variable=#  Define global variable for "storage" of#+ value of subshell variable.(echo "We are inside the subshell."echo "Subshell level INSIDE subshell = $BASH_SUBSHELL"inner_variable=Innerecho "From inside subshell, \"inner_variable\" = $inner_variable"echo "From inside subshell, \"outer\" = $outer_variable"global_variable="$inner_variable"   #  Will this allow "exporting"                                    #+ a subshell variable?)echo; echoecho "We are outside the subshell."echo "Subshell level OUTSIDE subshell = $BASH_SUBSHELL"echoif [ -z "$inner_variable" ]then  echo "inner_variable undefined in main body of shell"else  echo "inner_variable defined in main body of shell"fiecho "From main body of shell, \"inner_variable\" = $inner_variable"#  $inner_variable will show as blank (uninitialized)#+ because variables defined in a subshell are "local variables".#  Is there a remedy for this?echo "global_variable = "$global_variable""  # Why doesn't this work?echo# =======================================================================# Additionally ...echo "-----------------"; echovar=41                                                 # Global variable.( let "var+=1"; echo "\$var INSIDE subshell = $var" )  # 42echo "\$var OUTSIDE subshell = $var"                   # 41#  Variable operations inside a subshell, even to a GLOBAL variable#+ do not affect the value of the variable outside the subshell!exit 0#  Question:#  --------#  Once having exited a subshell,#+ is there any way to reenter that very same subshell#+ to modify or access the subshell variables?

⌨️ 快捷键说明

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