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

📄 ex10.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash#  Tip:#  If you're unsure of how a certain condition would evaluate,#+ test it in an if-test.echoecho "Testing \"0\""if [ 0 ]      # zerothen  echo "0 is true."else  echo "0 is false."fi            # 0 is true.echoecho "Testing \"1\""if [ 1 ]      # onethen  echo "1 is true."else  echo "1 is false."fi            # 1 is true.echoecho "Testing \"-1\""if [ -1 ]     # minus onethen  echo "-1 is true."else  echo "-1 is false."fi            # -1 is true.echoecho "Testing \"NULL\""if [ ]        # NULL (empty condition)then  echo "NULL is true."else  echo "NULL is false."fi            # NULL is false.echoecho "Testing \"xyz\""if [ xyz ]    # stringthen  echo "Random string is true."else  echo "Random string is false."fi            # Random string is true.echoecho "Testing \"\$xyz\""if [ $xyz ]   # Tests if $xyz is null, but...              # it's only an uninitialized variable.then  echo "Uninitialized variable is true."else  echo "Uninitialized variable is false."fi            # Uninitialized variable is false.echoecho "Testing \"-n \$xyz\""if [ -n "$xyz" ]            # More pedantically correct.then  echo "Uninitialized variable is true."else  echo "Uninitialized variable is false."fi            # Uninitialized variable is false.echoxyz=          # Initialized, but set to null value.echo "Testing \"-n \$xyz\""if [ -n "$xyz" ]then  echo "Null variable is true."else  echo "Null variable is false."fi            # Null variable is false.echo# When is "false" true?echo "Testing \"false\""if [ "false" ]              #  It seems that "false" is just a string.then  echo "\"false\" is true." #+ and it tests true.else  echo "\"false\" is false."fi            # "false" is true.echoecho "Testing \"\$false\""  # Again, uninitialized variable.if [ "$false" ]then  echo "\"\$false\" is true."else  echo "\"\$false\" is false."fi            # "$false" is false.              # Now, we get the expected result.#  What would happen if we tested the uninitialized variable "$true"?echoexit 0

⌨️ 快捷键说明

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