Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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` ?
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 "$@"
}
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.