Help Linux Shell Group exists

I am having some problems when writing shell as follows:
shell runs but returns no results

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....

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.

1 Like

Are you trying to see if a group already exists? If so, try this:

read -p "enter group name: " group
if grep -q $group /etc/group
then
   echo "group exits"
else
   echo "group not exits"
fi
2 Likes

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.

#/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:

if (( $a % 5 == 0 ))
then
  echo "$a is special"
else
  echo "$a is not special"
fi
1 Like

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.

thank sir. this's answers that I need