1 |
Donnie Berkholz wrote: |
2 |
|
3 |
> spec=$(echo ${CHOST} | cut -d- -f3) |
4 |
> |
5 |
You can do this without resort to an external process: |
6 |
IFS=- |
7 |
read _ _ spec _ <<< "$CHOST" |
8 |
unset IFS |
9 |
- or you can do: |
10 |
IFS=- |
11 |
arr=($CHOST) |
12 |
unset IFS |
13 |
spec=${arr[2]} |
14 |
- which is useful if you don't know how many elements there are. |
15 |
(IFS wouldn't affect the second assignment, but it's safest to unset it as |
16 |
soon as you've got whatever you needed with the non-default, ime.) |
17 |
|
18 |
Note that quoting is needed in the first one and will break the second one. |
19 |
In first instance the words are split before being read, and then the |
20 |
separator is not used at all, so first _ takes the whole line til the new |
21 |
line delimiter. In the second, it's the usual quote situation, so with |
22 |
quotes it's one parameter, without it's split according to IFS. |
23 |
|
24 |
|
25 |
-- |
26 |
gentoo-dev@g.o mailing list |