shell to delete a character variable, replace, capture, index and sliced

1. definition of variables, note = number without spaces on both sides; such as: a = www.xxxxx.oooo


2. The variable referenced by two methods: echo $ a or echo $ {a}


3. The acquisition variable length: echo $ {# a}


4. Remove variables: echo $ {a # ww} # w deleted from the beginning of two variable values, this does not affect the value of the original variable


Distinction 5. echo $ {a #.} And echo $ {a ##.}; And when a front to back table #, non-greedy, anchored to the first point;
  ## is from front to back, greed, the last stopping point;
6. the echo $ {.} a% and echo $ {a %%.} distinction; ibid., deleted from the back, and a non-greedy greedy


7. index and slice: echo $ {a: 5: 5} # Note that when the first 5 sections of several index starts from the back of the cut out several 5 represents


8. Replace Operation: echo $ {a / xxxxx / yy /} # The value of a is replaced xxxxx yy, usage style somewhat similar sed


Only when a replacement echo $ {a // x / X /} # // represents a greedy, replace all lowercase to uppercase x, use /: 9. Alternatively greedy


10. The unset command to cancel the setting variables: unset a # cancel a variable i.e.


11. Another variable is defined: echo $ {b-888} # if b been defined, even if it is not null alternative is 888; if not defined variable b, is defined, and assigned - after content


12.echo $ {b: -888} # b is not empty as long as the value of 888 will not be replaced or alternatively be 888;


13.echo $ {b: = 888} echo $ {b: +888} echo $ {b:? 888} There are these special usage, and remove: Usage numbers

Guess you like

Origin www.cnblogs.com/quzq/p/12104360.html