I have a bash shell script that requires ctrl-D to break out of the terminal.can anyone tell me how to use it in the shell script
ssh host last --->displays the list of users who were logged on to that host
I have different hosts the output is appended to one final and when I'm executing this particular shell script along with other series of commands, i'm using ctrl-D to see the output
suppose my shell script is myscript.sh to execute myscript.sh
./myscript.sh
ctl-D
connection to host closed
output is displayed
Instead, I want to use ctrl-D in my script file
There is no way to do this directly. Use a heredoc to feed stdin instead.
./someprog.sh << EOF
something here
EOF
You could try exec <&-
&-
is used to close a file descriptor (ps:everything in linux is a kind of file...)<&-
is closing file descriptor 0 = stdin - can also be written as 0<&-
If you open a normal terminal in your linux machine and type exec <&-
you will see your terminal to close/dissapear like if you press ^D.
PS1: Similarly, exec >&-
closes stdout
PS2: If you close stdin with exec <&-
you can re-open to continue your script with something like exec </dev/tty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With