简体   繁体   中英

Can you prompt for user input in a shell script that is running remotely?

Say I have a script that will be run on a remote machine. While running, the script computes some value. I want to prompt the user so she can change this value if needed. Is this possible?

I am running the script like: ssh $usr@$machine 'bash -s' < a.sh "param1" "param2"

In a.sh the read alternateValue function call seems to be ignored.

Or can anyone suggest a different approach?

The read statement reads data from stdin , but you are redirecting stdin in your command line with the < operator, so read isn't going to do anything useful.

What if you were first to copy the script over to the remote host, and then run:

ssh $usr@$machine 'bash /path/to/a.sh param1 param2'

Because there is no redirection happening here, read would work without a problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM