1

I'm really new at shell scripting and trying to create a loop that will continue to prompt a user for input until they confirm that it is correct. I'm attempting to use a while loop for this but it errors out with:

joyentmac2252:scripts jessebutryn$ ./bashprofilemod.sh
Please enter your Joyent Public Cloud (JPC) username and press [ENTER]: 
jesse.butryn
The username you entered is: jesse.butryn Is this correct? y/n :n
./bashprofilemod.sh: line 13: syntax error near unexpected token `fi'
./bashprofilemod.sh: line 13: `  fi'

The full script so far is below, sorry if it's really dirty but I'm still getting the hang of things. It's incomplete as of now because I'm trying to get the while loops to work before I move to the next steps.

#!/bin/sh
#Prompts user for their Joyent Cloud username (usually first.last)
read -p "Please enter your Joyent Public Cloud (JPC) username and press [ENTER]: " username
#Confirms user input
read -p "The username you entered is: $username Is this correct? y/n :" uconf
#
while [ $uconf = "N" -o $uconf = "n" ]
do
  read -p "Please enter your Joyent Public Cloud (JPC) username and press [ENTER]: " username
  read -p "The username you entered is: $username Is this correct? y/n :" uconf
  if [ $uconf = "Y" -o $uconf = "y" ]
    echo "Thanks your username will be entered as: $username$."
  fi
done

Thanks for any input

  • 1
    A pair of tips for better questions: 1. make a minimal test case. This is not bad, but if you make a shorter script with just the problem it is easier to understand. This could be reduced to one read before the loop and one loop and its contents. 2. make sure the output and the code match the error reported on line 24 is actually on line 20. – hildred Jun 27 '17 at 16:21
  • also note the redirection from /dev/tty is superfluous. – hildred Jun 27 '17 at 16:34
2

You have not used then for both the if statement.

if [ $uconf = "Y" -o $uconf = "y" ];then
    echo "Thanks your username will be entered as: ${txtcyn}$username${txtrst}."
 fi



 if [ $kconf = "Y" -o $kconf = "y" ];then 
     echo "Thanks your ssh public key will be entered as: ${txtcyn}$HOME/.ssh/$sshkey${txtrst}."
 fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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