So I am stuck on trying to create a bash script while loop function that takes the input from /etc/passwd and outputs how many of users use bash, nolongin, csh, and ksh. I believe I am supposed to use cat and cut. And I know that the type of shell a user uses is on the 7th field.
Am I correct in thinking that I should create a variable for each type of shell and increment it each time it finds a user that uses that particular shell?
So far this is the code I have but for some reason it only outputs the final if statement..
declare -i bash; declare -i nologin; declare -i csh; declare -i ksh; bash=0; nologin=0; csh=0; ksh=0; cat /etc/passwd | cut -d: -f7 $line | while read line; do if [ $line == "bash" ] then bash=bash+1; else fi [ $line == "/sbin/nologin" ] then nologin=nologin+1; else fi [ $line == "chs" ] then chs=chs+1; else then ksh=ksh+1; fi done
Update: So far I have changed the code and updated what I have. It loops through and gives out the correct portion of the if statement, but I am having trouble trying to increment the variables I have.