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

📄 ex9.sh

📁 一本完整的描述Unix Shell 编程的工具书的所有范例
💻 SH
字号:
#!/bin/bash# Variables: assignment and substitutiona=375hello=$a#-------------------------------------------------------------------------# No space permitted on either side of = sign when initializing variables.# What happens if there is a space?#  If "VARIABLE =value",#              ^#+ script tries to run "VARIABLE" command with one argument, "=value".#  If "VARIABLE= value",#               ^#+ script tries to run "value" command with#+ the environmental variable "VARIABLE" set to "".#-------------------------------------------------------------------------echo hello    # Not a variable reference, just the string "hello".echo $helloecho ${hello} # Identical to above.echo "$hello"echo "${hello}"echohello="A B  C   D"echo $hello   # A B C Decho "$hello" # A B  C   D# As you see, echo $hello   and   echo "$hello"   give different results.#                                      ^      ^# Quoting a variable preserves whitespace.echoecho '$hello'  # $hello#    ^      ^#  Variable referencing disabled by single quotes,#+ which causes the "$" to be interpreted literally.# Notice the effect of different types of quoting.hello=    # Setting it to a null value.echo "\$hello (null value) = $hello"#  Note that setting a variable to a null value is not the same as#+ unsetting it, although the end result is the same (see below).# --------------------------------------------------------------#  It is permissible to set multiple variables on the same line,#+ if separated by white space.#  Caution, this may reduce legibility, and may not be portable.var1=21  var2=22  var3=$V3echoecho "var1=$var1   var2=$var2   var3=$var3"# May cause problems with older versions of "sh".# --------------------------------------------------------------echo; echonumbers="one two three"#           ^   ^other_numbers="1 2 3"#               ^ ^#  If there is whitespace embedded within a variable,#+ then quotes are necessary.echo "numbers = $numbers"echo "other_numbers = $other_numbers"   # other_numbers = 1 2 3echoecho "uninitialized_variable = $uninitialized_variable"# Uninitialized variable has null value (no value at all).uninitialized_variable=   #  Declaring, but not initializing it --                          #+ same as setting it to a null value, as above.echo "uninitialized_variable = $uninitialized_variable"                          # It still has a null value.uninitialized_variable=23       # Set it.unset uninitialized_variable    # Unset it.echo "uninitialized_variable = $uninitialized_variable"                                # It still has a null value.echoexit 0

⌨️ 快捷键说明

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