j j S
j j S

Reputation: 56

How to fix "id -u" returning 0 into my variable for if statement?

I'm trying to put the result of "id -u $1" into a variable in order to verify it with an if statement but it seems like it's returning 0 into my variable even tho I've checked it and it's supposed to be 1008.Is it because the username is taken from the argument of the script?

UID=`id -u $1`
LOCK=`usermod -L $1`

if test $UID -lt 500;then

        echo "impossible to lock user"

else

        $LOCK;

fi

Upvotes: 2

Views: 670

Answers (1)

Romeo Ninov
Romeo Ninov

Reputation: 7245

Your problem is that you use system variable in your script and try to change it. instead of UID try to use UID1 (for example) as variable name. And your script will be something like:

UID1=`id -u $1`
LOCK=`usermod -L $1`

if test $UID1 -lt 500;then
        echo "impossible to lock user"
else
        $LOCK;
fi

Upvotes: 3

Related Questions