【问题标题】:Is this bash variable setting way correct这种 bash 变量设置方式是否正确
【发布时间】:2017-07-20 10:01:47
【问题描述】:

这种 bash 变量设置方式正确吗?请提供有关此用法的一些深入描述。

: ${AA="/root/"}

【问题讨论】:

    标签: bash variables


    【解决方案1】:

    您将使用此表单来设置一些默认值。例如

    default="/root"
    read -p "What is the directory? [$default] " AA
    : ${AA:=$default}  
    echo "Using: $AA"
    

    请注意,我在 ${AA:=...} 中添加了一个冒号,以便在变量为空时进行替换,而不仅仅是未设置(因为此处已设置)。

    请参阅手册中的Shell Parameter Expansion: 命令是documented here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 2023-04-10
      • 2017-08-18
      • 2012-08-30
      • 2018-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多