The Archives

  • 15.Nov.08
    Strings in bash shell | pfortuny | (0)
    Start with a string: $ a="hi, this is my beautifull string" Positional substrings: Substring from the 4th character on: $ echo ${a:3} this is my beautifull string Substring of length 4 from the 10th character: $ echo ${a:9:4} is m Substring modification: Substitute the first instance of a substring: $ echo ${a/full/ful} hi, this is my beautiful string Same example: $ echo ${a/h/H} Hi, this is my beautifull string Substitute all the instances of a substring: $ echo ${a//hi/HI} HI, tHIs is my beautifull string Substring removal: Remove the shortest match of a substring from the start: $ echo ${a#h*i} , this is my beautifull string Same, starting at the end $ echo ${a%i*g} hi, this is my beautifull str Remove the longest match of a ...