Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

detect tab from builtin bash read

26 views
Skip to first unread message

Sinbad s

unread,
Aug 17, 2017, 5:53:47 AM8/17/17
to
How to read tab from bash builtin read, The following doesn't seem to work.

mytab=`echo -e "\t"`

while IFS= read -e -i "$cmd" -p $prompt char
do
if [[ "$char" == "$mytab" ]]; then
echo "got tab"
fi
done

Ed Morton

unread,
Aug 17, 2017, 9:31:49 AM8/17/17
to

Teemu Likonen

unread,
Aug 17, 2017, 9:56:41 AM8/17/17
to
Sinbad s. [2017-08-17 02:53:41-07] wrote:

> How to read tab from bash builtin read,

while read -r -N 1 char; do
if [[ $char == $'\t' ]]; then
echo "That's the TAB key!"
fi
done

--
/// Teemu Likonen - .-.. <https://keybase.io/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///
signature.asc

Barry Margolin

unread,
Aug 17, 2017, 11:46:49 AM8/17/17
to
In article <4600785e-5390-4ffc...@googlegroups.com>,
The -e option means to use readline to allow input editing. Readline
normally uses the TAB key for completion, I don't think it will be put
into the variable.

And even if it is, $char contains the entire input line (which will
include any parts of $cmd that weren't edited away), not just a single
character. If you want to test if there's a TAB anywhere in the input,
you need a wildcard or regexp pattern.

BTW, you don't need that echo thing to get a tab into a variable, you
can simply do:

mytab=$'\t'

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0 new messages