-1

I am very new to writing Shell scripts and am trying to write a simple script to run Vagrant up then SSH into the box and run some commands. The echo Hi there will run but the read -p will never show. Am I doing this wrong or is there a work around of some sort?

vagrant ssh default << 'ENDSSH'
read -p "Enter your first name:" FIRST_NAME
echo Hi there
ENDSSH
1

1 Answer 1

0

Inside if a heredoc you can substitute variables, but it won't run any commands unless you put them in command substitution ($()). Put your read before the vagrant and use the resulting variable in your heredoc.

2
  • Thank you for the response! Would you happen to know another work around though? This is a basic example, but I want to call another script within the ENDSSH which has read in it but won't run inside there (the method you recommended just won't be applicable to my scenario). Any help is much appreciated.
    – Kevin
    Nov 19, 2018 at 2:06
  • Sorry for not noticing this comment earlier. Command substitution should let you do what you're looking for. gnu.org/software/bash/manual/html_node/…
    – chicks
    Jun 4, 2020 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.