Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Mar 1996 22:49:48 -0700 (MST)
From:      Don Yuniskis <dgy@rtd.com>
To:        freebsd-hackers@freefall.FreeBSD.org (FreeBSD hackers)
Subject:   /bin/sh tickler...
Message-ID:  <199603020549.WAA05932@seagull.rtd.com>

next in thread | raw e-mail | index | archive | help
Greetings, Earthlings (and those of you in the back row, too)!
     Apologies in advance for bothering the list with this one but I
couldn't think of a more knowledgable group to pass it by  (how's
that for "sucking up"???)  ;-)
     I was recently writing a few shell scripts and couldn't seem
to find a mechanism for processing tabs within a script!  Since
tabs are *so* pervasive, I can't imagine this is impossible.  Yet,
I can't find a way to do it...
     I started out with something like (not *really* this brainless...):

foo=`cat $bar | awk -- '/pattern/ { print "field1	field2" }'`
bar=`echo $foo | cut -f2`
echo $bar

which, curiously, choked because the tab between field1 and field2
had been replaced by a space.  Replacing it with a '\t' didn't help,
either.
     In playing with this, I've noted even simpler test cases that
yield "unexpected" results:

foo="a	tab"
bar='a	tab'
echo $foo
echo $bar

and, different shells respond differently (which, I guess, is to be
expected to some degree).
     I've since found a workaround for my original problem but this
one just nags at me begging for understanding.  I suspect it has to
do with the "substitution" performed by the shell in evaluating
these things.
     But, as I imagine this will bite me again at some time in the
future, I'd appreciate any words of wisdom/experience which could
help me avoid the same no-brainer mistake in the future.
     Thx,
--don



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199603020549.WAA05932>