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} //



  • 相关阅读:
    html 滚动条
    mybatis的select、insert、update、delete语句
    eclipse 删除工作空间中.metadata 再加入以前的maven项目编译出错解决方法
    JavaDailyReports10_18
    JavaDailyReports10_17
    JavaDailyReports10_16
    JavaDailyReports10_15
    JavaDailyReports10_14
    JavaDailyReports10_13
    JavaDailyReports10_12
  • 原文地址:https://www.cnblogs.com/huaxiaoyao/p/5995826.html
Copyright © 2011-2022 走看看