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.

2
  • 2
    Nope, you're doing it the correct way, if you want to do it with read. You can use awk or cut to only print the fields you need, and then you won't need the "rest" variable. But in general that's the way to go. Commented Dec 14, 2022 at 18:10
  • In fact, it is valid to discard any fields, not just the excess ones at the end, and to put all the unwanted data into the same variable. If you only want the third and fifth fields, this works: read -r X X third X fifth X. Commented Dec 15, 2022 at 9:40