How to use double or single brackets, parentheses, curly braces

后端 未结 7 786
心在旅途
心在旅途 2020-11-21 23:10

I am confused by the usage of brackets, parentheses, curly braces in Bash, as well as the difference between their double or single forms. Is there a clear explanation?

7条回答
  •  梦毁少年i
    2020-11-21 23:36

    Truncate the contents of a variable
    
    $ var="abcde"; echo ${var%d*}
    abc
    
    Make substitutions similar to sed
    
    $ var="abcde"; echo ${var/de/12}
    abc12
    
    Use a default value
    
    $ default="hello"; unset var; echo ${var:-$default}
    hello
    

提交回复
热议问题