zoukankan      html  css  js  c++  java
  • shell parameter expansitions

    type test
    type -a test

    math calculate:
    echo $((1+2*3))

    parameter expansition:
    bash-4 introduced features:
    var=student
    echo ${var^}  //Student
    echo ${var^^} //STUDENT
    var=STUDENT
    echo ${var,}  //sTUDENT
    echo ${var,,} //student
    bash2 introduced features:
    ${var//PATTERN/STRING}:replace all instances of pattern with string
    passwd=12345678
    printf "%s " "${passwd//?/*}" //********
    ${var:OFFSET:LENGTH}:return a substring of $var
    var=student
    echo ${var:0:3} //stu
    POSIX SHELL
    posix shell introduced some expansions from kornshell.
    main returning the length and removing a pattern from the beginning
    or end of a variable's contents.
    ${#var}:length of variable's contents
    var=student
    echo "${#var}" //7
    ${var%PATTERN}:remove the shortest match from the end
    var=tomorrow
    echo ${var%o*} //tomorr
    ${var%%PATTERN}:remove the longgest match from the end
    var=tomorrow
    echo ${var%%o*} //t
    ${var#PATTERN}:remove the shortest match from the beginning
    var=tomorrow
    echo ${var#*o} //morrow
    ${var##PATTERN}:Remove the longest match from the beginning
    echo ${var##*o} //w

    ${var:-default} and ${var-default}: use default values
    ${var:-default}
    if the var is unset or empty, then use default
    var=
    echo ${var:-default} //default
    unset var
    echo ${var:-default} //default
    ${var-default}
    if the var is unset , then use default , just this case
    unset var
    echo ${var-default} //default
    var=
    echo ${var-default} //



  • 相关阅读:
    项目Alpha冲刺(团队6/10)
    项目Alpha冲刺(团队5/10)
    项目Alpha冲刺(团队4/10)
    项目Alpha冲刺(团队3/10)
    项目Alpha冲刺(团队1/10)
    Alpha代码规范、冲刺任务与计划
    团队作业第六次—团队Github实战训练
    Alpha冲刺(8/10)——2019.4.30
    Alpha冲刺(7/10)——2019.4.29
    Alpha冲刺(6/10)——2019.4.28
  • 原文地址:https://www.cnblogs.com/huaxiaoyao/p/5995826.html
Copyright © 2011-2022 走看看