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
  • 2
    this solution also has the benefit that if delimiter is not present, the var2 will be empty Commented Jan 11, 2018 at 4:34
  • The read does not work inside loops with input redirects. read will pick a wrong file descriptor to read from.
    – akwky
    Commented Feb 24, 2020 at 10:59
  • I initially gave this answer a plus as an elegant solution, but now figured out it works differently on Bash v3 and v4, thereby doesn't work on macos with pre-installed bash v3. Unfortunatelly I can't downvote the answer now since the vote is locked :( Commented Nov 11, 2020 at 14:30
  • A more general, correct, way: IFS=- read -r -d '' var1 var2 < <(printf %s "ABCDE-123456"). The -r -d '' and <(printf %s ...) are important
    – Fravadona
    Commented Jan 21, 2022 at 10:22
  • 1
    @akwky: Use an alternate file descriptor. while read -r line <&3; do ssh_or_something "$line"; done 3<file Commented Jun 24, 2022 at 0:14