Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 6
    cut works, but I Dennis' answer is better and more flexible. Does anyone know if it spawns a new process like cut?
    – JoBu1324
    Commented Feb 20, 2014 at 18:06
  • 4
    It's better to use Bash's built-in parameter expansion features than generating subshells running tools like basename and cut, see Dennis's answer below Commented Jun 14, 2016 at 17:32
  • 2
    cut can read from stdin, so it is better especially when you have a very long string that you need to process, like the contents of a file.
    – Sahas
    Commented Apr 26, 2017 at 8:34
  • 2
    And how would this be applied to hello: world. This is half an answer.
    – basickarl
    Commented Oct 9, 2017 at 12:20
  • It can be done using subsitution syntax also like {var/:/''}, but works only in bash..
    – Mahesh
    Commented Feb 14, 2019 at 11:40