Sponsored By

Sign in to follow this  

For Loop Is Failing

Recommended Posts

I was just messing around using a for loop. I would assume my for loop would work on every item in this substitution `ps -Ao comm`, it does not. As soon as I enter "yes" in my input, it executes the command echo $i, then stops. Why is it not looping until every item in `ps -Ao comm` has been used as a variable?


for i in $(ps -Ao comm)
do echo "do you want to kill the following process [y/n], or enter [exit] to quit"
echo $i
read IN
case $IN in
[yY]|[yY][eE][sS]) exec echo $i;;
[nN]|[nN][oO]) echo "continuing to next process";;
exit) exit;;
*) echo "process ignored, continuing to next";;

one more thing, the command "exec" seems useless. What purpose does it serve?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this