[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: Dave Gibson
Subject: Re: corrupted input after size function (input that's not recorded by bash)
Date: Fri, 14 Jun 2013 14:08:08 +0100
User-agent: tin/2.1.2-20121224 ("Langholm") (UNIX) (Linux/3.0.0-1 (i686))

Linda Walsh <address@hidden> 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.

Ignored or executed as a separate command?

Using bash 4.2.45, "echo ls /" is treated as "echo ; ls /" although
as you've noticed the command appears in the history as-typed.

> 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?

Trial and error suggests it's something to do with new-style command
substitution.  Try backticks:

    local s=`stty size`

> (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?

  local o="(${LINES}x${COLUMNS})" ; local s="${o//?/\\b}" ; printf "$o$s"

reply via email to

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