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 checkUser Test code
sudo local/checkuser.sh misitio test 7.3 abkrim /home/abkrim/Sites/ abkrim.EXISTS user exists But 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 checkUser Test code
sudo local/deploy_site.sh misitio test 7.3 abkrim /home/abkrim/Sites/ abkrim user does not exist 11 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>&1 silently 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.