Help Linux Shell Group exists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Linux Shell Group exists
# 1  
Old 04-05-2012
Help Linux Shell Group exists

I am having some problems when writing shell as follows:
shell runs but returns no results
Code:
echo "enter group name: "
            dir="/home"
            read group
            if id -g $group > /dev/null 2>&1
            then
            echo "group exits"
            else
            echo "group not exits"
            fi;;

can you help me!
thank very....
# 2  
Old 04-05-2012
You have a syntax error. The double semicolons are not needed at the end of your fi

I also don't know about your version of id, but the one installed on my version of linux accepts a -g option, but not with an additional parameter. If the return is always false, you might want to read the man page for the id command.
This User Gave Thanks to agama For This Post:
# 3  
Old 04-06-2012
Are you trying to see if a group already exists? If so, try this:
Code:
read -p "enter group name: " group
if grep -q $group /etc/group
then
   echo "group exits"
else
   echo "group not exits"
fi

These 2 Users Gave Thanks to fpmurphy For This Post:
# 4  
Old 04-06-2012
hey guys, i can not run this script, as it says, Line 4: [: too many arguments, i am new in scripting
question is write a script in which user type the number and if its divisible by 15 and get remainder 0, then it is a unique number otherwise not a unique number.
Code:
#/bin/bash
echo "write the number"
read a
if [ $a % 15 -eq 0 ];
then
  echo "$a is special"
else
  echo "$a is not special"
fi

please help in solving this, i am having very hard time with this.

Last edited by Franklin52; 04-06-2012 at 07:51 AM.. Reason: Please use code tags for data and code samples, thank you
# 5  
Old 04-06-2012
Quote:
Originally Posted by ping2
hey guys, i can not run this script, as it says, Line 4: [: too many arguments, i am new in scripting
question is write a script in which user type the number and if its divisible by 15 and get remainder 0, then it is a unique number otherwise not a unique number.
Code:
#/bin/bash
echo "write the number"
read a
if [ $a % 15 -eq 0 ];
then
  echo "$a is special"
else
  echo "$a is not special"
fi

please help in solving this, i am having very hard time with this.
@ping2, please start a new thread for your question next time rather than post it in an existing thread! Thanks.

Regarding your question you can try this:
Code:
if (( $a % 5 == 0 ))
then
  echo "$a is special"
else
  echo "$a is not special"
fi

This User Gave Thanks to Franklin52 For This Post:
# 6  
Old 04-06-2012
ok thanks franklin and sorry to write in the middle of the thread, as that was my first question in this form, i have never used this before, thanks for your help.
# 7  
Old 04-10-2012
Quote:
Originally Posted by fpmurphy
Are you trying to see if a group already exists? If so, try this:
Code:
read -p "enter group name: " group
if grep -q $group /etc/group
then
   echo "group exits"
else
   echo "group not exits"
fi

thank sir. this's answers that I need
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search for Multiple strings in a given date range and print the Group if they exists

Hi, I am Searching for Multiple strings in a given date range and print the Group if they exists. the below is the format: ------------------------------------------------------------------------------------------------------------------------- ID: FIRST ID MESSAGE: Event Message... (5 Replies)
Discussion started by: linuxuser999
5 Replies

2. Shell Programming and Scripting

Determine a shell variable exists in file?

Hi Folks, Trying to build up a script that will lookup a username invoked as: ./buildscript.sh <username> This should take <username> and look it up in <username_file> and prepare for further processing. Here is the snippet that isn't working just right: user=$1 if ]; then echo... (1 Reply)
Discussion started by: gdenton
1 Replies

3. Shell Programming and Scripting

C shell scripting, check if link exists on remote servers

Hi, I'm new to C Shell programming. I'm trying to check if a sym link exists on remote server if not send email. I'm not having much luck. Can anyone help? Here is what I have written but it doesn't work. It tells me that my variable was not defined. Here is part of the script, the second... (0 Replies)
Discussion started by: CDi
0 Replies

4. Shell Programming and Scripting

Check if user exists shell

Hello! I'm stuck with a problem that i can't solve. I'm very new to unix, linux and shell scripting i might add. I'm trying to create a script that will execute as follows: First start the script - sh exist Then the prompt asks the user to input a username to check if it exists within the... (6 Replies)
Discussion started by: bib2006
6 Replies

5. Shell Programming and Scripting

Checking if file exists using a NOT operator and shell variable

Hi, I'm new to UNIX, at least shell programming and am having trouble figuring out a problem i'm having. In one section in my nested if statement, i want the program to test if the file does not exist, based on an argument supplied at the command line by the user. What i have is elif ; then... (3 Replies)
Discussion started by: rowlf
3 Replies

6. Shell Programming and Scripting

Shell script to check if any file exists in 4 folders

Hi All, working on AIX 5.3. Requirement is: Shell script in ksh to check if any file exists in 4 folders as below: 1. /FILE/INB/INT1 2. /FILE/INB/INT2 3. /FILE/INB/INT3 4. /FILE/INB/INT4 Thanks a lot for your time! a1_win. (3 Replies)
Discussion started by: a1_win
3 Replies

7. Shell Programming and Scripting

HOW TO CHECK ONLY .C FILES EXISTS OR NOT IN A FOLDER using IF in C shell script?

Hi friends.. I hav a problem.... I dont know how to check .c files exists r not in a folder using IF in C shell script actually i tried like this if(=~ *.c) even though some .c files or there in the current folder..it is not entering int o the if control statement...... (17 Replies)
Discussion started by: p.hemadrireddy
17 Replies

8. Shell Programming and Scripting

Chek if a file exists in Ubuntu and Cent OS using shell script

I have tried few examples in the internet but all of them are different and none worked. I need to check if a file exists in a directory if it does not then exit . here is what I have for now $filename ="/usr/local/net/var/lib/directoryservice/sync.disable" if ; then echo "The file exists"... (2 Replies)
Discussion started by: m_kk
2 Replies

9. UNIX for Dummies Questions & Answers

If file exists (bourne shell)

Im trying to code some logic into a test script to test for the existence of a file before recreating it. Im using the following line to test for this: if -r test.txt; However I get the error message ./testScript.sh: -r: not found Having read through the man pages im still not clear whats... (2 Replies)
Discussion started by: blakmk
2 Replies
Login or Register to Ask a Question