Bash --- columns problem ??

Dean S. Messing deanm at sharplabs.com
Sun Dec 16 05:04:52 UTC 2007


Steven W. Orr wrote:
<snip>
: Why use grep or pr or any other shellout when you can just do it right 
: from within bash?
: 
: myRead()
: {
:     typeset line1, line2, line3
:     read line1
:     read line2
:     read line3
:     echo "$line1 $line2 $line3"
:     [[ -n "$line1" && -n "$line2" && -n "$line3" ]]
: }
: while myRead
: do
:     :
: done < /usr/share/dict/words 


I could be wrong, but to answer your question:

1) Because `pr --columns=3' is a whole lot easier to type than what you suggest

2) Because what you suggest has a bug, at least on my machine.
   When I run it, I get


==>./foo
./foo: line 3: typeset: `line1,': not a valid identifier
./foo: line 3: typeset: `line2,': not a valid identifier
./foo: line 3: typeset: `line1,': not a valid identifier
./foo: line 3: typeset: `line2,': not a valid identifier
./foo: line 3: typeset: `line1,': not a valid identifier
./foo: line 3: typeset: `line2,': not a valid identifier
./foo: line 3: typeset: `line1,': not a valid identifier

and so forth


3) Because your suggestion would give the opposite of what I would
   expect if I were asked to turn the following into three columns:

a
b
c
d
e
f
g
h
i
j
k
l

I would want:

a  e  i
b  f  j
c  g  k
d  h  l

Yours will give:

a  b  c
d  e  f
g  h  i
j  k  l

Dean




More information about the users mailing list