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.

Required fields*

5
  • I think you are pretty close. But now it will fail if there is a | in the string :P . Could you think of a way to escape it (without breaking something else)? Commented Feb 6, 2013 at 19:58
  • I think it doesn't matter what character or sequence you chose, there is always a risk that it will be in "wrong" place. If you want to keep some of the suggestions here and not rewrite it totally a test can be added to be 100% sure. Some code that chose delimiter (| in the above) from a list of characters, finding the first that isn't in the string. Then use that instead of always using |. E.g. characters to use/test: |;,&% etc. Commented Feb 6, 2013 at 20:40
  • Updated the answer, but sooner or later it will be better to write it better in some other language, e.g. ruby. I finally added a better(?) alternative, but that isn't using split in one line (as the OP wants?). Commented Feb 7, 2013 at 11:04
  • You can use \0 as a delimiter, since this isn't allowed in string data anyways (try var=$'foo\0bar'; echo "$var"). This is what my suggested answer does. Commented Feb 8, 2013 at 18:04
  • Thanks for the tip, but \0 doesn't work, I think IFS needs something apart from NULL character. But I tried with \1 instead, and it seems to work, and good to learn more about $'' syntax, thanks. I will do a last update, but perhaps the OP doesn't have a real problem to solve, it feels more like a quiz. Commented Feb 8, 2013 at 21:03