BASH – Tips and tricks
Bash Variable String Manipulation
1 2 3 4 5 6 7 8 9 10 11 12 13 |
A = "123456" # This prints the chars from 3 to 5 # Chars are counting from [0] echo ${A:3:5} # prints "456" echo ${A:1:4} # prints "2345" # Prints the number of chars echo ${#A} # prints "6" |
Front Match These are the examples of a front matching Front is meant to be “left to right” matching
1 2 3 4 5 6 7 |
a = "blog.gryzli.info" echo ${a#*.} # prints "gryzli.info" echo ${a##*.} # prints "info" |
Rear Match These are the examples of a rear matching Front is meant to be “right to left” matching a = “blog.gryzli.info” echo ${a%.*} # prints “blog.gryzli” echo ${a%%.*} #… Continue reading BASH – Tips and tricks