You need to use `-t` option in `ssh` to assign a pseudo-terminal to `ssh` session:
ssh -q -t root@server 'bash test.sh'
I have a script on my server named `test.sh`:
#!/bin/bash
read -p "Select an option [1-4]: " option
echo "You have selected $option"
When I run it through ssh manually, I see this:
me@me:~$ ssh root@server
root@server's password:
[...]
root@server:~# bash test.sh
Select an option [1-4]: 48
You have selected 48
When I run it as ssh remote command, I see this:
me@me:~$ ssh root@server 'bash test.sh'
root@server's password:
48
You have selected 48
I am unsatisfied with this output because it's missing `Select an option [1-4]: ` prompt string and the original script which from has I derived `test.sh` contains a lot of interactive dialogue strings like this and I need them all.
I know that `read` prints it's prompt to `stderr` so I tried to start the script with following commands in case if stderr is omitted, but the output stays still the same:
ssh root@server 'bash test.sh >&2'
ssh root@server 'bash test.sh' >&2
ssh root@server 'bash test.sh 2>&1'
ssh root@server 'bash test.sh' 2>&1
Why this is happening and how to make ssh remote command work as expected?
https://stackoverflow.com/questions/45838637/ssh-remote-command-not-working-as-expected-problems-with-read
linux - ssh remote command not working as expected (problems with read) - Stack Overflow