1

I have two parameters: the list of linux group of user

groupsUsers=$(id -nG ${utilisateur})

the list of all the group linux of users (linux groups + applications)

list_all_groups=$(curl -u GET "${edge_admin_nodes}_${port_http}"/applications/lists)

How can I test if the groupsUsers exist in list_all_groups or no, and in the case "no" I store the result in a variable ?

I did this solution but I'm not sure that working.

for groupUser in ${groupsUsers}
do 
if echo "$list_all_groups" | grep -o "$groupUser" then

        echo "${groupUser}"


    then
        my_result=$( echo "$groups,$groupUser" )
         result="${groups},\"${groupUser}\""
fi
done
2
  • What format does $list_all_groups have? Commented Jun 26, 2018 at 14:59
  • list_all_groups= Appli_1,Appli_2,Appli_3, group_linux_2 and the groupsUsers = group_linux_1, group_linux_2, group_linux_3 Commented Jun 26, 2018 at 15:03

1 Answer 1

3

Generally, I prefer proper parsing. However, a common solution is to put the delimiter around both strings, e.g.:

if echo ",$list_all_groups," | grep -q ",$groupUser," then

This checks a string that has commas around the original list (so we don't have to deal with beginning/end-of-string differences) against a particular entry, also with its delimiters, so that we don't match a groupUser of foo with an entry in list_all_groups of foobar.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.