简体   繁体   中英

Erroneously using STDIN when pasting a script into the Terminal.app

I have the following script-snipped, which I use regularly to semi-automate one of my workflows. I open a bash terminal and start irb and then paste the script:

require 'highline/import'

# ...
user = ask("User:")
repo = ask("Repository:")
# ...
# Do advanced fancy stuff

Now I want to be able to paste this into the terminal, but the first prompt for the user is overwritten by the following line: repo = ask("Repository:") .

Is there a way to prevent this behaviour.

I know that I could write a script. But

  1. I find it convenient to be able to just paste this into the terminal
  2. I wonder how the STDIN can be somehow outfoxed in this case

Is there a way to prevent this behaviour.

You can prevent the echoing of pasted text with the command

stty -echo

- whether you like that is another question, since this inevitably also prevents the echoing of typed-in commands, but you can see again after entering

stty echo

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