Gentoo Archives: gentoo-user

From: Pandu Poluan <pandu@××××××.info>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] is a nice "place" :-D
Date: Tue, 17 May 2011 14:35:36
Message-Id: BANLkTimf-xJuR5vdrsJsm88EOC=gWjHuqg@mail.gmail.com
In Reply to: Re: [gentoo-user] is a nice "place" :-D by Alex Schuster
1 On 2011-05-17, Alex Schuster <wonko@×××××××××.org> wrote:
2 > Juan Diego Tascón writes:
3 >
4 >> I have always wondered if there is a way to do awk '{ print $1}' using
5 >> only builtin bash functions when you only have a one line string
6 >
7 > str="one two five"
8 >
9 > # remove all from the first blank on, but will not work with
10 > # other whitespace
11 > echo ${str%% *}
12 >
13 > or
14 >
15 > # set $1, $2, $3, ... to words of $str
16 > set $str
17 > echo $1
18 >
19 > or
20 >
21 > # create array holding one word per element
22 > strarr=( $str )
23 > echo $strarr (or echo ${strarr[0]})
24 >
25 > Wonko
26 >
27 >
28
29 How about this:
30
31 str="one two three"
32 read word etc <<< "$str"
33 echo $word
34
35 (not tested, though)
36
37 --
38 Pandu E Poluan - IT Optimizer
39 My website: http://pandu.poluan.info/