"hi" appears on th...">

Arrow key via stdin

I am trying to send an arrow key through stdin in bash:

cat | / ben / bash

then I type "echo hi" => "hi" appears on the console (of course, without quotes) then I press the up arrow => ^ [[Command not found

Is it possible to send an arrow button to a program via stdin?

The reason I ask: I want to control bash from another program. I would like to send arrow keys in bash

+3
source share
3 answers

, , -tty- ( openpty() ), bash PTY PTY. . "-" GNU C.

+5

bash -i.

0

Do not use cat. Use the Bash builtin command readwith the parameter -eto enable readline support.

# version 1
while IFS="" read -r -e -d $'\n' line; do printf '%s\n' "$line"; done | /bin/bash

# version 2
#set -o pipefail
# kill 0: kill process group
(
while IFS="" read -r -e -d $'\n' line; do 
   #trap 'trap - EXIT HUP INT QUIT PIPE TERM ERR; kill $PPID' EXIT HUP INT QUIT PIPE TERM ERR 
   trap 'trap - EXIT HUP INT QUIT PIPE TERM ERR; kill 0' EXIT HUP INT QUIT PIPE TERM ERR 
   printf '%s\n' "$line" >> ~/.bash_history
   history -n
   printf '%s\n' "$line" 
done 
) | (trap 'trap - EXIT HUP INT QUIT PIPE TERM ERR; kill 0' EXIT HUP INT QUIT PIPE TERM ERR; /bin/bash)
#) | (trap 'trap - EXIT HUP INT QUIT PIPE TERM ERR; kill $PPID' EXIT HUP INT QUIT PIPE TERM ERR; /bin/bash)
0
source

Source: https://habr.com/ru/post/1724040/


All Articles