Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash read -p doesnt work [duplicate]

Tags:

linux

bash

shell

When running my shell script I get this error:

': not a valid identifiere 17: read: `

Here is my shell script:

#!/usr/bin/env bash
# Mr. Robot Install Wordpress Script
# Script is used for the following:
# add user to server
# change to new user home directory
# download latest version of wordpress
# unzip wordpress
# move all files up a directory level
# move up a directory level
# delete wordpress.zip
# remove wordpress folder
echo "/*****************************************************/"
echo "/************** HELLO MR. ROBOT **********************/"
echo "/*****************************************************/"
echo ".."
echo ".."
echo "Website URL" 
echo 'url: \r'
read -p $website 
echo 'User: \r' 
read -p $newuser
echo 'Pass: \r'
read -p $password 
echo "creating account......"
/scripts/wwwacct $website $newuser $password 0 x3 n n n  0 0 0 0 0 0
echo "Changing Directory....."
cd ~/home/$newuser/
echo "Getting Latest Version of Wordpress!"
curl -O http://wordpress.org/latest.tar.gz 
echo "Tarball Incoming!!"
tar xvzf latest.tar.gz
echo "removing tar file"
rm latest.tar.gz
echo "moving wordpress folders!"
cp -a ~/home/$newuser/public_html/wordpress/. ~/home/$newuser/public_html/
cd /home/$newuser/public_html/
echo "Part 01 Complete!!"
exit

I've tried to use different versions of the read line with -p or -e. Any help would be appreciated. I've even tried adding it on a separate line with input.

EDIT: Updated file to where it takes inputs, but issue is that the inputs are not being used through the rest of the script. Thus causing errors for directories not being found.

like image 454
ZackAttack Avatar asked Nov 22 '25 17:11

ZackAttack


1 Answers

Don't quote the variables names. read needs the name of the variable to assign to, not its value, which is what you get if you have a dollar sign $.

read -p 'website url: ' website 
read -p 'Username: ' newuser
read -p 'Password: ' password 

It looks like one of the variables holds \r, a carriage return. The error message that bash is trying to print is something like:

bash: ./script: line 17: read: `\r': not a valid identifier

But \r causes the cursor to go back to the beginning of the line, causing ': not a valid identifier to overwrite the beginning of the message.

like image 106
John Kugelman Avatar answered Nov 24 '25 08:11

John Kugelman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!