I see a lot of examples about check if user exists in *nix system using id
For test my code i've create a simple code and after check and verify work I've copied to develop script
checkuser.sh
#!/usr/bin/env bash
function checkUser() { if id "$USER" >/dev/null 2>&1; then echo "user exists" else echo "user does not exist" fi
}
USER=$4
checkUserTest code
sudo local/checkuser.sh misitio test 7.3 abkrim /home/abkrim/Sites/
abkrim.EXISTS
user existsBut when copy in my script not work
#!/usr/bin/env bash
if [ $EUID != 0 ]; then sudo "$0" "$@" exit $?
fi
SITE=$1
PHP=$3
USER=$4
NGINX=/etc/nginx/
FPM=/etc/php/${PHP}/fpm/pool.d/
PATH=$5
checkUserTest code
sudo local/deploy_site.sh misitio test 7.3 abkrim /home/abkrim/Sites/
abkrim
user does not exist 1 1 Answer
PATH is in the environment, it is special. After your script does PATH=$5, it's no longer able to find the id executable; therefore this
id "$USER" >/dev/null 2>&1silently fails.
You probably do not want to overwrite PATH. You probably want your variables in lower case.
However if you really want to overwrite PATH, then you should later use full path to any executable that shouldn't depend on the new ("custom") PATH. E.g. /usr/bin/id.