I have a bash script that I wrote to automate some commands, and one of the first lines in the script isn't working on the computer that it needs to run on. The code is below

#some comments
read -p 'press enter to begin'
echo "Please Wait..."
#rest of the script

It is a fairly simple start to the automation script and it works fine on the virtual machine I used to test and run the script, but when the script runs in the working environment it outputs the text read -p 'press enter to begin' straight to the command line and then stops running; instead of the desired result of a read command with the prompt press enter to begin, waiting for the user's input, and then echoing Please wait... while the script runs.

sudo bash ./path/to/file.sh

I am not sure what to do to fix this problem as I can't find anything else about this online.

I've gone through all the basic troubleshooting steps; made sure the file is executable, run while specifying that it is a bash file (it actually wouldn't run without the bash callout), and running the same read command that is in the script directly on the command line (which outputs the desired result of press enter to begin and waiting for a user input). Any suggestions? I plan on running the script using the set -x command when have a chance today or tomorrow.

closed as off-topic by roaima, Kusalananda, ilkkachu, jimmij, X Tian Feb 26 at 17:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – roaima, Kusalananda, ilkkachu, jimmij, X Tian
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Of course it'll wait after printing press enter to begin; you're reading a line of text from the user with that as the prompt. Or are you saying that it prints literally read -p 'press enter to begin' when it's run? If so, please edit your question to explain exactly how you're running the script. – roaima Feb 19 at 15:00
  • indeed, you've asked it to read something into the REPLY variable; did you hit ENTER at the prompt? Do you want the user to "press enter to begin"? – Jeff Schaller Feb 19 at 15:40
  • @roaima I clarified the problem statement. The script literally outputs read -p 'press enter to begin' when its run. – Josey ٌّ Feb 19 at 15:59
  • 1
    OK. So how (exactly) does this script get run? – roaima Feb 19 at 16:06
  • 4
    Voting to close as unreproducible, because the OP hasn't confirmed the script in the question is exactly what's triggering the problem. We can't make accurate assessments on approximations. – roaima Feb 20 at 15:58

I figured out why the script was breaking, when using the read command I had

read -p 'prompt'

Instead of

read -p "prompt"

When I changed it to the double quotes the script ran fine for the beginning part that I was asking about in this question. Why did this specific format break the script? Idk, the machine I'm running it on is very picky and has some weird formatting preferences about things that should work, and do work in other environments.

  • 2
    This should not have changed anything. Using "prompt" or 'prompt' is exactly equivalent if the string prompt is static. Do you have a quote somewhere earlier in the program that is not closed? – Kusalananda Feb 20 at 18:38
  • This is literally the beginning of the program and it ran fine on the virtual machine, I have no clue why it did this – Josey ٌّ Feb 20 at 18:42
  • You had #some comments as the second line? – roaima Feb 20 at 23:20
  • yeah I had a few lines of comments that are irrelevant to the issue I was having – Josey ٌّ Feb 21 at 13:11
  • I don't think they were irrelevant. There is nothing wrong with what you've shown here. Therefore there must have been something strange with the part(s) you've omitted. – roaima Feb 21 at 14:38

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