[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: corrupted input after size function (input that's not recorded by ba

From: Chris F.A. Johnson
Subject: Re: corrupted input after size function (input that's not recorded by bash)
Date: Thu, 13 Jun 2013 17:38:32 -0400 (EDT)
User-agent: Alpine 2.02 (DEB 1266 2009-07-14)

On Thu, 13 Jun 2013, Linda Walsh wrote:
I have a small function in my bashrc:

function showsize () {\
 local s=$(stty size); local o="(${s% *}x${s#* })"; s="${#o}";\
 echo -n $o; while ((s-- > 0));do echo -ne "\b"; done; \
export -f showsize
trap showsize SIGWINCH
That has the effect of showing me my current window size
when I resize it.

The odd thing is, if I use it while at a bash input prompt --
any command I type has the first word ignored.

so if I type:
echo cmd

If 'cmd' is not a typo you can use command-not-found to lookup the package that contains it, like this:
   cnf cmd
But then I re-edit the line (in vi-mode, ESC-k, it shows me I typed
echo cmd -- and, indeed, if I hit return, it echo's the word 'cmd' w/no error.

So how can my showsize function be mangling the input in a way that
prevents proper execution, but isn't recorded by bash?

(this has been one of those things that's bothered me for years, but
never been important enough to even ask about... I thought I'd look at it
to fix it, but still don't see why it does what it does).

Any clues?

   The baskspaces (\b) are erasing your input, not the function's

   Chris F.A. Johnson, <http://cfajohnson.com/>
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]