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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this