0

Hey Guys i want to split a string into two seperate, e.g. resolution=1024x786 to width=1024 and height=786. To do this, i found that code:

set -- "$resolution"
IFS="x"; declare -a coordinates=($*)

Source But now are all my Variables that contain an "x" in any position split there. How can use this "IFS" just for my $resolution?

Thanks for your Help :)

Community
  • 1
  • 1

1 Answers1

3

One solution

IFS=x read -r -a coordinates <<<"$resolution"

If you actually want the values in separate variables:

IFS=x read -r width height  <<<"$resolution"
rici
  • 234,347
  • 28
  • 237
  • 341