LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-28-2012, 04:26 AM   #1
darkkatana
LQ Newbie
 
Registered: Oct 2012
Location: Leeds UK
Distribution: Mint/Arch
Posts: 3

Rep: Reputation: Disabled
[SOLVED]Basic If statments problem


Hi, im trying to create my first script for an Administrator to install users in debain(Ive noticed differences between debian and Opensuse in scripting/commands)and I'm haing having problems with the if statment. so far this is what I have written:

Code:
echo "Would you like to create a new user?(yes/no)"
read input
continue =$(yes)
if [ "$input" -ge "$continue" ]
then
echo "Please enter new user name"
                read UN
                useradd -m $UN
        echo "Please enter a password for $UN"
                passwd $UN
        echo "User '$UN' has been created"
fi
echo "Opperation cancelled"

but when i run the script I recieve this out put:

Code:
Would you like to create a new user?(yes/no)
yes
and then nothign after that, not even the treminal chevrons...

so basically im a little lost on what to do at the moment and help would be much apprecieated. also if there are any good online guides could somewone point them out please.
Thanks for reading.

Last edited by darkkatana; 11-28-2012 at 05:55 AM. Reason: Solved
 
Old 11-28-2012, 04:38 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Try running the "yes" command in the terminal... That's why it doesn't terminate. You wanted:

Code:
continue="yes"
(and your if condition should probably be
Code:
if [ "$input" == "$continue" ]
)

Hope this helps,
 
Old 11-28-2012, 04:48 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Problem is with password line as you cannot supply password in advance in script itself, plus there's little syntax error. I tried to correct it, so once try it:
PHP Code:
echo "Would you like to create a new user?(yes/no)"
read input
if [ $input -eq "yes" ];
then
echo -"Please enter new user name: "
read UN
useradd 
-m $UN
passwd $UN  
## No need to do echo, but it will ask you to enter password
echo "User $UN has been created."
elif $input -eq "no" ]; then
echo "Opperation cancelled."
fi
fi 
Or you can do it in one more way as:
PHP Code:
case $choice in
yes
) echo -"Please enter new user name: "
read UN
passwd $UN
;;
no) echo "Opperation cancelled."
exit 0;;
*) echo 
"Enter a correct choice (yes/no):"
$(basename $0

Last edited by shivaa; 11-28-2012 at 04:55 AM.
 
Old 11-28-2012, 05:55 AM   #4
darkkatana
LQ Newbie
 
Registered: Oct 2012
Location: Leeds UK
Distribution: Mint/Arch
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
Try running the "yes" command in the terminal... That's why it doesn't terminate. You wanted:

Code:
continue="yes"
(and your if condition should probably be
Code:
if [ "$input" == "$continue" ]
)

Hope this helps,
thanks this helpped alot(it's working now)
and thanks shiva for pointing out those errors.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic routing problem. stefaandk Linux - Networking 2 06-14-2006 01:43 AM
basic piping problem corck Programming 4 08-01-2005 03:30 AM
OOo BASIC problem kovard Linux - Software 2 11-08-2004 11:08 AM
Very basic problem with Samba Fruitbat Linux - Networking 11 09-08-2004 04:29 AM
Perm Routes and Arp Statments. Ox///M Linux - Networking 2 01-11-2002 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration