Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail From: Chet Ramey Newsgroups: gnu.bash.bug Subject: Re: ${var@P} expansion includes 0x01 and 0x02 Date: Fri, 6 Nov 2015 08:51:30 -0500 Lines: 44 Approved: bug-bash@gnu.org Message-ID: References: <20151027210241.GJ27325@eeg.ccf.org> <5630D3C5.3040000@case.edu> Reply-To: chet.ramey@case.edu NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1446817927 13753 208.118.235.17 (6 Nov 2015 13:52:07 GMT) X-Complaints-To: action@cs.stanford.edu Cc: Greg Wooledge , bug-bash , chet.ramey@case.edu To: Dennis Williamson Envelope-to: bug-bash@gnu.org X-Enigmail-Draft-Status: N1110 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.563CB062.01FF, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2015-08-12 04:07:17, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 4a9dbf1319b80202fd0da142137dff50 X-Junkmail-Whitelist: YES (by domain whitelist at mpv1-2015.case.edu) X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.563CB064.01F1,ss=1,re=0.000,fgs=0, ip=0.0.0.0, so=2015-08-12 04:07:17, dmn=2011-05-27 18:58:46 X-Mirapoint-Loop-Id: bf8563d3e1ac351bbf6ce762bbe5f26d X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 129.22.103.226 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11844 On 11/5/15 7:45 PM, Dennis Williamson wrote: > That's what the \[ and \] escape sequences expand to and use to > communicate information to readline about invisible characters in the > prompt (RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE). If you want to > use the expansion of ${var@P} as, for instance, the prompt passed to > readline when using `read -e -p prompt', those characters need to be there. > > > To follow on to what Greg said: > > The only way I've found to output a string containing non-printing sequence > delimiters using the @P transformation is to use read -e -p or to strip the > \[ and \] first. All the other prompt escapes work in printf or echo -e > when using @P. Let's stipulate that you're talking about interactive shells here, since line editing is turned off in non-interactive shells, and \[ and \] only expand to \001 and \002 when line editing is enabled. (Though what I describe here works in non-interactive shells, too.) You can get the results you want by toggling the `emacs' option, or `vi' if that's what you prefer. Since \[ and \] expand to special readline characters only when readline (and therefore line editing) is enabled, and you don't want them expanded, then you should disable readline. You can disable line editing with `set +o emacs +o vi' (whichever is appropriate). Run the following script to see what I mean: P='\[vis0\]\w\$\[vis1\] ' echo "${P@P}" | cat -v set -o emacs echo "${P@P}" | cat -v set +o emacs +o vi echo "${P@P}" | cat -v -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/