1 |
Juan Diego Tascón writes: |
2 |
|
3 |
> I have always wondered if there is a way to do awk '{ print $1}' using |
4 |
> only builtin bash functions when you only have a one line string |
5 |
|
6 |
str="one two five" |
7 |
|
8 |
# remove all from the first blank on, but will not work with |
9 |
# other whitespace |
10 |
echo ${str%% *} |
11 |
|
12 |
or |
13 |
|
14 |
# set $1, $2, $3, ... to words of $str |
15 |
set $str |
16 |
echo $1 |
17 |
|
18 |
or |
19 |
|
20 |
# create array holding one word per element |
21 |
strarr=( $str ) |
22 |
echo $strarr (or echo ${strarr[0]}) |
23 |
|
24 |
Wonko |