I am working on a script to delete users from text file. However, before deleting, I want to check if any process by a user is running and if running then kill all the processes and delete.Here's how I'm doing this:    if    #user doesn't exists then print user not existelsepids = `ps U $name -o pid | head -n -1`     if [ -n $pids ]    then    for pid in $pids    do        sudo kill -KILL $pid    donefi     sudo userdel $name -r -f        echo            echo The user - $name - has been deleted!    echo    fi    done < $fname                         # double-quote fname    echoSo, basically its a loop to delete users and in that an if statement to make sure no process is being run by a user and if its being run then force close processes and delete user.However, Its not working and it says pids: command not found.. Any solution, how to fix it?
Checking and Killing processes of a user before deleting
bash;shell script
You have the following code:pids = `ps U $name -o pid | head -n -1`bash is picky about whitespace, here. Simply remove the spaces from pids = ... and it will work as intended:pids=`ps U $name -o pid | head -n -1`