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?
-
Please show your coding efforts.Cyrus– Cyrus2017-08-15 16:46:25 +00:00Commented Aug 15, 2017 at 16:46
Add a comment
|
2 Answers
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.
1 Comment
Sergio Abreu
Saved lives! Tks
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