zoukankan      html  css  js  c++  java
  • shell 中"${b2}" and "${b:2}"

    在看 学习shell中练习的代码

    #!/bin/bash
    # User can keyin filename to touch
    3 new files.
    PATH
    =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    export PATH

    echo
    "I will use 'touch' command to create 3 files."
    read
    -p "Please input the filename what you want: " fileuser

    filename
    =${fileuser:+"filename"}

    date1
    =`date --date='2 days ago' +%Y%m%d`
    date2
    =`date --date='1 days ago' +%Y%m%d`
    date3
    =`date +%Y%m%d`

    file1
    ="$filename""$date1"
    file2
    ="$filename""$date2"
    file3
    ="$filename""$date3"

    touch $file1
    touch $file2
    touch $file3

    中的 filename=${fileuser:+"filename"}对于:+不是很明白,然后查了下用法。

    lx@ubuntu:~/bsh/scripts$ b=""
    lx@ubuntu:~/bsh/scripts$ c="Z"
    lx@ubuntu:~/bsh/scripts$ echo a=${a-1}, b=${b-2}, c=${c-3}
    a=1, b=, c=Z
    lx@ubuntu:~/bsh/scripts$ echo a=${a:-1}, b=${b:-2}, c=${c:-3}
    a=1, b=2, c=Z
    lx@ubuntu:~/bsh/scripts$ 
    

    +----------------------------------------------------------------------+
    |Form		     Meaning					       
    +----------------------------------------------------------------------+
    |${variable:?word}   Complain if undefined or null		       
    |${variable:-word}   Use new value if undefined or null		       
    |${variable:+word}   Opposite of the above			       
    |${variable:=word}   Use new value if undefined or null, and redefine. 
    +----------------------------------------------------------------------+


  • 相关阅读:
    建筑经济与企业管理 【1090】
    31 任意进制计数器的构成方法1
    30 同步计数器
    29 典型的时序电路模块2
    STM32的FSMC详解
    28 典型的时序电路模块1
    27 FSM,时序电路的分析方法
    26 电路结构和逻辑功能的关系
    25 触发器逻辑功能的分类
    24 触发器的电路结构和动作特点
  • 原文地址:https://www.cnblogs.com/lxgeek/p/1962380.html
Copyright © 2011-2022 走看看