Advertisement
harsh7i

StringStartEnd.sh

Mar 1st, 2023
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.33 KB | None | 0 0
  1. $ string="hello-world"
  2. $ prefix="hell"
  3. $ suffix="ld"
  4.  
  5. $ #remove "hell" from "hello-world" if "hell" is found at the beginning.
  6. $ prefix_removed_string=${string/#$prefix}
  7.  
  8. $ #remove "ld" from "o-world" if "ld" is found at the end.
  9. $ suffix_removed_String=${prefix_removed_string/%$suffix}
  10. $ echo $suffix_removed_String
  11. o-wor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement