Reputation: 3
Im quite new to bash scripting and I tried checking through the previous examples of this error but I still dont undertand why this isnt working
Here is the snippit of code throwing up the error:
#!/bin/bash
function group_check(){
if [[getent group | awk -F":" '{print$1}' -eq $1 ]] ; then
echo "The user exists!"
else
echo "The user doesn't exist!"
fi
}
group_check tim
group_check tam
Hopefully someone cant point out where im going wrong or perhaps even suggest a better way of doing this, but I would quite like to understand where im going wrong.
Thanks
Upvotes: 0
Views: 1647
Reputation: 241988
If you want to compare output of a command to a number, you have to enclose the command into $(...)
to capture its output:
if [[ $( getent group | awk -F":" '{print$1}' ) -eq $1 ]] ; then
Note that the space after [[
isn't optional.
Also note that -eq
compares numbers, you should use ==
for string comparison.
Upvotes: 2