LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-26-2003, 11:26 PM   #1
Psykoral
LQ Newbie
 
Registered: Jun 2003
Distribution: Mandrake 9.1
Posts: 20

Rep: Reputation: 0
Unhappy Specify "and" or "also" in BASH '


OK, so I need to know how specify a command to run ONLY if two different items are answerd correctly.... here's what I mean...

========================================

echo -n "Do you need to create a new user for this Domain? [y/n]: "
read newuser
if test "$newuser" = "y"
then
echo -n "New Username: ";
read newusername;
else echo "No New users added, continuing with domain setup...";
fi
if test "$newuser" = "y"
then
echo -n "$newusername shall be added to what group? (leave blank for users): "
read grouptest
fi
if test "$grouptest" = ""
then
/usr/sbin/useradd -m -c '' -d /home/$newusername -s '/bin/bash' -G '' -e '' $newusername;
/usr/bin/chage -m -1 -M 99999 -W -1 $newusername;
passwd $newusername;
/usr/sbin/usermod -g users $newusername;
fi
######## Work in Progress ############
#if test "$newuser" = "y" 'and' "$grouptest" = "*"
# group=$grouptest #Redundant? no, I use $group later ;c)
# /usr/sbin/useradd -m -c '' -d /home/$newusername -s '/bin/bash' -G '' -e '' $newusername;
# /usr/bin/chage -m -1 -M 99999 -W -1 $newusername;
# passwd $newusername;
# groupadd $group
# /usr/sbin/usermod -g $group $newusername;
# echo "Continuing with domain setup...";
#fi
========================================

K, so ya see where I have "$grouptest" = ""... well for the 'if' statement which I hope to follow what you see above, I need to specify a couple things... One, anything other then 'nothing' entred (I had hoped "$grouptest" = "*" would work )
as well as listening if both these tests pass... kind of like a....

if test "$newuser" = "y" 'and' "$grouptest" = "*"

I know what your thinking "Why don't you just make it an "else" or "elif" statement instead? Well, I'll tell you why...

Can't do 'elif' cause I dont know what they are going to enter as $grouptest

Can't do 'esle' because that will execute the rest of the commands to add a new group when the person didn't even want to add a new user!!! lol. It's probably something I've overlooked in the 'man bash' or online, but I can't seem to find the answer... Anyone l337 enough to help this n00b starving for information?
 
Old 12-27-2003, 12:10 AM   #2
Psykoral
LQ Newbie
 
Registered: Jun 2003
Distribution: Mandrake 9.1
Posts: 20

Original Poster
Rep: Reputation: 0
Ah ha! Guru friend of a freind had the answers I was looking for! For anyone interested...

To specify more then one if:
if [ "$newuser" = "y" ] && [ -z "$grouptest" ]

oh, and the -z "$grouptest" is basicallly "$grouptest" = "null" ...
so...

if [ "$newuser" = "y" ] && [ "$grouptest" ]

asks if $newuser was answered "y" and if $grouptest had something other then Null/nothing/blank.

Thanks again Sloth1200!!!!!
 
Old 12-27-2003, 12:17 AM   #3
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
if [[ ${newuser} = "y" && ${grouptest} = "*" ]]; then
do it up
fi

...I think that's right anyway....

....k....nevermind... =o)
 
  


Reply



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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
Where to download precompiled bash binaries, such as "time" and "top"? elinuxqs Linux - Newbie 12 11-14-2005 08:36 PM
bash equivalence of tcsh "alias em "emacs \!:1 &""? rgiggs Slackware 3 07-29-2004 02:07 AM
bash-2.05b# Xlib: extension "XFree86-DRI" missing on display ":0.0". citrus Linux - General 8 02-22-2004 10:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:13 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
Open Source Consulting | Domain Registration