Donnie Berkholz wrote:

> spec=$(echo ${CHOST} | cut -d- -f3)
> 
You can do this without resort to an external process:
IFS=-
read _ _ spec _ <<< "$CHOST"
unset IFS
- or you can do:
IFS=-
arr=($CHOST)
unset IFS
spec=${arr[2]}
- which is useful if you don't know how many elements there are.
(IFS wouldn't affect the second assignment, but it's safest to unset it as
soon as you've got whatever you needed with the non-default, ime.)

Note that quoting is needed in the first one and will break the second one.
In first instance the words are split before being read, and then the
separator is not used at all, so first _ takes the whole line til the new
line delimiter. In the second, it's the usual quote situation, so with
quotes it's one parameter, without it's split according to IFS.


-- 
[EMAIL PROTECTED] mailing list

Reply via email to