10

I made a bash script to use sendmail to send emails. However, when it asks for input, whenever I try to use the arrow keys to correct a typo, instead of moving the cursor, it just adds ^[[D to the end. How can I fix that?

1
  • Please show your coding efforts. Commented Aug 15, 2017 at 16:46

2 Answers 2

20

Use the -e option to read. From the bash manual:

-e
Readline (see Command Line Editing) is used to obtain the line. Readline uses the current (or default, if line editing was not previously active) editing settings.

Sign up to request clarification or add additional context in comments.

1 Comment

Saved lives! Tks
0

If I understood what you want. I searched a long time and did not find example until now so I am not sure this is the best method.

Then you can use arrows to get the history of the shell and what you passt in the past or write in a read cmd.

echo "Give your TV video : " 
read -e -i "" filev # assign read input to $filev, "" is to avoid to write something, do not know why, this is different than read -p "Give your TV video" filev
echo $filev >> ~/.bash_history # write what was written or paste in history
history -a # actualize the sheel history with the ~/.bash_history to get the $filev available in the shell after

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.