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.
if
-then
-else
blocks (although look also atcase
and think about whether that makes more sense for you). Also look at how to do arithmetic with shell variables. And read cut(1) to see how to get it to process data on the command line; and if you find a way, let me know, because I don't know of any (hint hint). Finally, learn about UUoC.