LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-25-2012, 04:29 PM   #1
burkecabaniss
LQ Newbie
 
Registered: Jul 2007
Location: San Antonio, Texas
Posts: 10

Rep: Reputation: 1
bash builtin read problem; backspace retained ?


Since install of fc16 to replace fc13 the bash builtin read always provides an invalid value when the backspace key is used. The value echoes properly, but it is as if the backspace and the character it erases are retained in the environment value and used in non-echo applications.

I test by read of a known file name, then testing file existence. Every file and every time it fails if backspace is keyed but does not fail otherwise. The environment values always echo the proper name.

Is this a read -r setting ? If so how can I set not raw ?

For over 10 unix/linux years I have not experienced this.
 
Old 09-25-2012, 04:53 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Can you post the transcript of a terminal session to show us exactly what is happening?
 
Old 09-26-2012, 12:22 PM   #3
burkecabaniss
LQ Newbie
 
Registered: Jul 2007
Location: San Antonio, Texas
Posts: 10

Original Poster
Rep: Reputation: 1
read builtin problem; hex 08 (backspace) in environment variable

Script started on Wed Sep 26 11:42:40 2012
bsamain01(BSA)1 #>TEST
KEY COBOL PROGRAM NAME IN /usr/bsa/cbl - ACH00N
Find program ACH00N
KEY COBOL PROGRAM NAME IN /usr/bsa/cbl - ACX\bH00N
NO /usr/bsa/cbl/ACX\bH00N
KEY COBOL PROGRAM NAME IN /usr/bsa/cbl - MADR\b30D
NO /usr/bsa/cbl/MADR\b30D
KEY COBOL PROGRAM NAME IN /usr/bsa/cbl - MAD30D
Find program MAD30D
KEY COBOL PROGRAM NAME IN /usr/bsa/cbl -

while [ -z "$DONE" ]
do unset REPY
echo "KEY COBOL PROGRAM NAME IN /usr/bsa/cbl - \c"
read REPY
: ${REPY:='NONE'}
if [ -s /usr/bsa/cbl/$REPY ]
then echo "Find program $REPY"
else echo "NO /usr/bsa/cbl/$REPY"
fi
done
exit

Above are the transcript and my script TEST. I edited the transcript only to exchange symbols '\b' for backspace hex 08 characters, to delete control characters in the command prompt, and to delete stuff at the end related to killing the session. I just wanted it to be readable and relevant.

I was wrong. The environment variable holds the \b and echoes it. I don't know enough Unix basics to know whether this is a read problem, and environment variable problem, or a command interpreter problem. I still suspect the first.
 
Old 09-26-2012, 09:06 PM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Wait do you mean \b is retained (saved to REPY) with slash '\' but you expect it to be just 'b'? Or do you mean that the '\b' in inputs (e.g. "KEY COBOL PROGRAM NAME IN /usr/bsa/cbl - ACX\bH00N") was control characters and that you just replaced it with '\b' here (in this post) (e.g. was really "KEY COBOL PROGRAM NAME IN /usr/bsa/cbl - ACX?H00N") to make it presentable to us? Please clarify.

Last edited by konsolebox; 09-26-2012 at 09:08 PM.
 
Old 09-27-2012, 08:31 AM   #5
burkecabaniss
LQ Newbie
 
Registered: Jul 2007
Location: San Antonio, Texas
Posts: 10

Original Poster
Rep: Reputation: 1
I explained that I edited to exchange \b symbols for non-text hex 08 characters in the transcript, and the purpose was readability (presentation). I chose to use \b rather than \010 (octal). Both are common usage for representation of backspace character value.

No symbols '\' or non-capital letters 'b' were in the original transcript before my editing. None such were keyed or echoed.
 
Old 09-27-2012, 09:05 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
That's weird. Could be bash or something related to the terminal. What happens when you run 'reset' or 'tput reset'?
 
Old 11-08-2012, 04:48 PM   #7
burkecabaniss
LQ Newbie
 
Registered: Jul 2007
Location: San Antonio, Texas
Posts: 10

Original Poster
Rep: Reputation: 1
bash builtin read problem; backspace retained

I have further learned that `read -e` (READLINE) does process the Backspace key as delete the character to the left of the cursor and place the cursor there (rubout). This is how previous fedora versions of `read` worked, and what I want instead of the problem explained previously.

But I do not want to research and revise all my scripts that use `read`. I might `enable -n` (disable) the read builtin and replace it with a function or alias, except that I believe these require a read program file, and there is none now. yum finds none.

The above method (adding -e option) worked for the echo builtin because /bin/echo exists.

Is there a shell option to do this, or another way to cause `read` to be `read -e` ?
 
1 members found this post helpful.
Old 11-08-2012, 08:02 PM   #8
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by burkecabaniss View Post
I have further learned that `read -e` (READLINE) does process the Backspace key as delete the character to the left of the cursor and place the cursor there (rubout). This is how previous fedora versions of `read` worked, and what I want instead of the problem explained previously.
First, thanks for telling us the solution. I would apply this to my scripts.

Quote:
Is there a shell option to do this, or another way to cause `read` to be `read -e` ?
I wonder if creating a function that would wrap the builtin function could fix that. Functions are called first before builtins.
Code:
read() {
    builtin read -e "$@"
}
# or
function read {
    builtin read -e "$@"
}
I prefer the latter
 
Old 11-09-2012, 08:36 AM   #9
burkecabaniss
LQ Newbie
 
Registered: Jul 2007
Location: San Antonio, Texas
Posts: 10

Original Poster
Rep: Reputation: 1
Thank you for the info on how to refer to the read program as "builtin read -e". I handled it as you suggested and as I had previously handled the "echo -e" problem, by a function in /etc/bashrc. This changes the default actions, but echo can also always be executed as /bin/echo and read also as builtin read.
 
Old 11-09-2012, 06:23 PM   #10
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by burkecabaniss View Post
but echo can also always be executed as /bin/echo and read also as builtin read.
So is there something more missing? Calling external 'echo' is sometimes not a good idea as well. One of the reasons is that '/bin/read' runs slow naturally as it has to be called as an external binary.
 
Old 11-10-2012, 09:06 AM   #11
burkecabaniss
LQ Newbie
 
Registered: Jul 2007
Location: San Antonio, Texas
Posts: 10

Original Poster
Rep: Reputation: 1
You misunderstand. I have no /bin/read. yum for fc16 would not add it. I did not know how to set up a read function without /bin/read. I did not know that I could reference "builtin read". Learning that solved my problem of how to change the default behavior of read, to solve the backspace problem.

What I wrote about echo was only an explanation of how I previously solved a similar problem. I knew how to set up the function. I did have a /bin/echo. I had no /bin/read and didn't know about the "builtin" reference technique.
 
Old 11-10-2012, 11:05 AM   #12
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Sorry what I actually meant was /bin/echo. Ok I understand.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: Is there a builtin command to write lines? stf92 Programming 22 07-26-2012 12:24 PM
Make Ctrl + backspace work in bash TiredOfThis Linux - Software 6 01-28-2010 08:05 AM
[SOLVED] bash invocation question, using 'history' builtin. bartonski Programming 9 10-18-2009 09:00 PM
[SOLVED] extracting floating numbers from variable using bash's builtin string chopping billywayne Programming 24 07-19-2009 09:13 AM
bash scripting: tilde expansion with the read builtin EtienneG Programming 4 09-26-2007 04:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration